Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 15910

How to bind data to the form in symfony

$
0
0

I have a variable that need to be bind into a form in symfony, how can I bind data from action file to form?

The Action File $this->unitCost = $this->getUser()->getAttribute('unit_cost'); $value_lists = ($this->unitCost);

    foreach($value_lists as $values)        {        echo $values['unit_cost'];        }    $form = new MyForm(); $form->bind(array('unit_cost' => $values['unit_cost']));     //print_r($value_lists);

Formpublic function configure() {

    $cost_range[''] = '-- Please select --';    for ($i = 0; ($i <= 100); $i++) {        $cost_range[$i] = $i;    }    $this->setWidgets(array('user_id' => new sfWidgetFormDoctrineChoice(array('model' => 'Person', 'add_empty' => '-- Please select --'), array('onchange' => 'filerUnitCostByName()', 'id' => 'user_id')),'unit_cost' => new sfWidgetFormSelect(array('choices' => $cost_range), array('id'=>'unit_cost')),    ));

How can I display the bind value through the number drop down through the FormI am taking data from a dropdown and putting in to a session, and then retrieve the data in the action. I want to set the selected variable in a dropdown created in the form created in with widget. as u can see in the widget area. I want to add the value as default value.


Viewing all articles
Browse latest Browse all 15910


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>