php - IF Statement inside a ChoiceType Symfony2 -


how place if statement inside choicetype add option?

this code:

        $form = $this->createformbuilder()         ->add('name', choicetype::class, array(             'choices' => array(                 'server' => 'server',                 'apc' => 'apc',                 'switch' => 'switch',                 'apc small' => 'apc small'             ), 

the choice apc need checked first see if exists. if not exists had included otherwise excluded.

the check ready true , false how place if statement inside form add array. or there other way that?

the if statement this:

if($apcdisable == false){} 

not sure understand problem, can determine/calculate choices array content before adding form, example this

// w/out apc $choices = [     'server' => 'server',     'switch' => 'switch',     'apc small' => 'apc small' ]; if($apcdisable == false) {     // add apc choice, since it's available     $choices['apc'] = 'apc'; } $form->add('name', choicetype::class, [     'choices' => $choices, ]); 

if can calculate $apcdisable only based on form data, can use form events described in http://symfony.com/doc/current/cookbook/form/dynamic_form_modification.html.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -