tags:

views:

357

answers:

1

the code in symfony that i am using, $this->setWidgets(array( 'mobile' =>new sfWidgetFormInput(), 'subscribetosms' =>new sfWidgetFormInputCheckbox(), )); i want to validate the checkbox, and also code to take values from check box

+1  A: 

to validate form fields in symfony u need to set validators like this (assuming you are in a form class):

$this->setValidators(array(
      'mobile'          => new sfValidatorString(array(...)),
      'subscribetosms'  => new sfValidatorInteger(array(...))
    ));

Question is, what do you want to validate? If you want some kind of value send to your php script if the checkbox is selected you need to set this value in the widget.

new sfWidgetFormInputCheckbox(array('value_attribute_value'=>'your_value' )

Now you could configure your validator to validate this value (sfValidatorString for a string, of sfValidatorInteger for an integer).

To get the value in your action after the validation:

if ($this->form->isValid()) {
  $myValue = $this->form->getValue('subscribetosms');
}
samsam