Question

I have a form created with Symfony forms.

and in the template i have this selectbox, displayed on the page with the render method.

<?php echo $form['field']->render() ?>

is it possible to set the selected option of this select box?

Or does this have to be done in the class that creates this form? There is the creation of the field done:

public function configure() {
    $this->widgetSchema['field'] = new sfWidgetFormSelect(
      array("choices" => 
          array('1' => 'test1','2' => 'test2')
      )
    );
  }
Was it helpful?

Solution

yes, sure — you should have set corresponding form value — either via bind(), either via widget's default option.

For example,

public function configure() 
{
    $this->widgetSchema['field'] = new sfWidgetFormSelect(array(
        "choices" => array('1' => 'test1','2' => 'test2'), 
        'default' => 2));
}

Hope I've answered your question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top