Search code examples
phpformscheckboxsymfony1

How to set sfWidgetFormInputCheckbox default to false inside form class?


I've got a form class with a checkbox widget:

$this->setWidgets(array(
  'status' => new sfWidgetFormInputCheckbox(array('value_attribute_value' => 1)),
  // various other widgets
));

Is there a way to set this checkbox to unticked from inside the form class (it's checked by default)? I can't seem to get anything to work. I found something on Google that this might be a Symfony bug that just hasn't been fixed but I'm refusing to believe it.

Setting it from the action works fine:

$this->form->setDefault('status', false);

... but I'd prefer not to have it there.


Solution

  • Try setting the default value at the end of the configure() method of your form, it should work :

    $this->setDefault('status', false);