I have a custom Form I’ve made that extends the Doctrine base forms for a Doctrine object.
I have a database field that is type: boolean. For my form, I have this represented by a sfWidgetFormInputCheckbox() widget. When my form is submitted, the value of my checkbox comes back as on if it was checked and if it wasn’t checked, then no value is passed. Either way, when I do my $form->save(), the boolean field is not affected. Symfony/Doctrine wants to see a true or false. Not a on or no value at all.
My solution is just to see if the value was passed at all and if so, then that field is true else false:
$values['my_field'] = isset($values['my_field']) ? true : false;
Is this the proper way to handle this? I would think that Symfony/Doctrine would already understand how to handle checkboxes. I would expect it to know that if the value for the checkbox comes back as on then to set that value in the database as true and if it doesn’t exist, then it’s false.
Obviously my approach works… but what is the CORRECT approach?
sfValidatorBooleanreturns true or false. If you are not getting true or false after binding the form, you are not using this validator.