php - Symfony2 : set default value from database in radio buttons choice form? -


new symfony2, have simple table 2 fields.

as alert field boolean, declared form this:

public function buildform(formbuilderinterface $builder, array $options) {     $builder                                         ->add('message', 'text', array('label' => "message"))                         ->add('alert', 'choice', array(               'choices'   => array(1 => 'yes', 0 => 'no'),               'expanded'  => true,               'multiple'  => false,               'label'     => "are agree?",               'attr'      => array('class' => 'well')         )); } 

it working when create new entry, when trying edit entry, 'alert' choice stored in database not set in form (radio button).

how can set database state of field in form?

you have 2 options here.

try use data attribute in formbuilder.

$builder                                         ->add('message', 'text', array('label' => "message"))                         ->add('alert', 'choice', array(               'choices'   => array(1 => 'yes', 0 => 'no'),               'expanded'  => true,               'multiple'  => false,               'label'     => "are agree?",               'data'      => $entity->getalert(),               'attr'      => array('class' => 'well')         )); 

or: when creating form in symfony pass along data entity form. auto fills values.

$this->createform(new formtype(), $entity); 

Comments

Popular posts from this blog

symfony - InvalidConfigurationException in SecurityExtension.php line 429: No authentication listener registered for firewall "secured_area" -

angular ui router - 10 digest iterations reached in angularjs when using $state.go -

javascript - Handling constructor related functions while testing with mocha and sinon -