How to select multiple symfony flags when editing an object

I have a symfony 1.4 application and in the form I use sfWidgetFormChoiceto create multiple checkboxes.

I can set the default values ​​without problems, but after saving the object and viewing the edit form, I can not check the boxes.

Values ​​from the 'checked' flags are inserted and stored in one field.

For instance:

Default checkbox setup

This is the default setting. This is stored in the database as Full-Time;Hourly. This works great.

When I edit this object, the form looks like this:

Edit checkbox setup

The function setDefaultdoes not work when editing an object (because there is "data" there, so we do not need a default value).

How do I create a field object:

$choices    = array(
    'Full-Time' => 'Full-Time',
    'Part-Time' => 'Part-Time',
    'Hourly'    => 'Hourly',
    'Contract'  => 'Contract'
);

$this->widgetSchema['emp_type'] = new sfWidgetFormChoice(
    array(
        'choices'   => $choices, 
        'multiple'  => true, 
        'expanded'  => true
        ),
    array()
);

$this->setDefault('emp_type', array('Full-Time', 'Hourly'));

?

+3
1

sfWidgetFormChoice:: render() , $value . , , :

Widget, sfWidgetFormChoice. :

  
public function render($name, $value = null, $attributes = array(), $errors = array())    {
  $value = explode(';', $value);
  return parent::render($name, $value, $attributes, $errors);
}

, sfWidgetFormChoice:: render() $ ( ).

+2

All Articles