views:

332

answers:

1

OK, I have one form with another embedded form. In actions.php I have:

...
// add extra field - select for dynamic population
$tempFrm = new SbCarteOpTempForm(array(), array('type' => 'transfer'));
$tempFrm->setWidget('inv_selectate',new sfWidgetFormSelectMany(array('choices' => array())));
$tempFrm->setValidator('inv_selectate', new sfValidatorPass());

$tempFrm->setWidget('status',new sfWidgetFormInputHidden(array(),array('value'=>'pending')));
$tempFrm->setValidator('status', new sfValidatorPass());

The extra fields "inv_selectate" and "status" should be included in displayed form, and they are indeed. But when I try to submit form, only status variable is sent, the select element is not (inv_selectate).

Why is this happening? I really don't see the problem (and neither the difference between these two new added fields.

Thanks.

+1  A: 

I found it :)

It's related to the select element. Inside the template I use js to add elements to it (dynamically populated by user), but the select won't appear in form submission unless you have some elements selected within!

In my case the selected has only elements, none selected. D'oh! :)

Cristian N
if you need to ensure there is always a value, you could try creating a custom widget that contains a select and a hidden widget (take a look at how sfWidgetFormDateRange works - you can copy it, it does something similar with two sfWidgetFormDate objects)
benlumley