vendredi 24 avril 2015

Symfony 2 - Checkbox with default Value unless Data From Database

I have a check box that Renders correctly . If there is no data from the database I want the check box to be checked by default.

If I set "data" = True it displays the checkbox checked. Now if I get the data from the database it won't override the checkbox to the boolean value of false. If I remove the data" => true then I am able to get the correct checkbox from the database but I am not able to set the default checkbox.

    public function buildForm(FormBuilderInterface $builder, array $options)
{

    $builder
        ->add('isFieldFirstname', 'checkbox', array(
        'label'    => 'Show First Name',
        'required' => false,
            "data" => true,
            )
                )

Just to recap

  1. Database - No record found - show default checkbox as checked
  2. If record found use value from database ex isFieldFirstname = false checkbox unchecked



Aucun commentaire:

Enregistrer un commentaire