Note that there are some explanatory texts on larger screens.

plurals
  1. POSF 1.4 Unexpected extra form fields in an embedform (to update tables)
    text
    copied!<p>Good morning.<br> I'm here to solicit the community about <strong>embedded forms with Symfony 1.4</strong>.<br> I have <strong>two models, with a relation one-to-many</strong>.<br> I <strong>generate the first model and all its dependencies before to show the form</strong>.<br> I always get those errors :<br> <code>modelb: Unexpected extra form field named "0". Unexpected extra form field named "1". Unexpected extra form field named "2". Unexpected extra form field named "3". Unexpected extra form field named "4". Unexpected extra form field named "5". Unexpected extra form field named "6". Unexpected extra form field named "7". Unexpected extra form field named "8". Unexpected extra form field named "9". Unexpected extra form field named "10". Unexpected extra form field named "11".</code> I also tried with <code>embedRelation()</code> and I got the same. Here are summaries of the two <strong>model schemas</strong> : </p> <pre><code>ModelA: columns: model_d_id: { type: integer, notnull: true } comments: { type: string(1024), notnull: false } relations: ModeleD: ... ModelB: columns: model_a_id: { type: integer, notnull: true } model_b_id: { type: integer, notnull: false } model_c_id: { type: integer, notnull: true } is_selected: { type: boolean, notnull: true } relations: ModelA: class: ModelA local: model_a_id foreign: id onDelete: CASCADE foreignAlias: ModelB ModelB: ... ModelC: ... </code></pre> <p>So, in the form I want to be able to update the <code>comments</code> of <code>ModelA</code>, and to have checkboxes for <code>is_selected</code> for each entry of <code>ModelB</code> related to the current ModelA.<br> Here is what the form looks like : </p> <pre><code>[] modele_b_entry_name_1 [] modele_b_entry_name_2 [] modele_b_entry_name_3 text [_______________________________] [ Submit ] </code></pre> <p>Here is the code of <strong>the embedded form</strong> : </p> <pre><code>class ModelBForm extends BaseModelBForm { public function configure() { unset($this['model_a_id'], $this['model_b_id'], $this['model_c_id'], $this['updated_at']); $model_a = $this-&gt;getObject(); $this-&gt;setWidget('is_selected', new sfWidgetFormInputCheckbox( array('label' =&gt; $model_a-&gt;ModelC-&gt;getName()), array() )); $this-&gt;setValidator('is_selected', new sfValidatorBoolean()); } } </code></pre> <p>Here is the <strong>collection of the previous embedded form</strong> :</p> <pre><code>class ModelBCollectionForm extends sfForm { public function configure() { $all_model_b = Doctrine_Query::create() -&gt;from('ModelB p') -&gt;where('p.model_a_id = ?', $this-&gt;getOption('model_a_id')) -&gt;execute(); foreach ($all_model_b as $index =&gt; $model_b) { $form = new ModelBForm($model_b); $this-&gt;embedForm($index, $form); } } } </code></pre> <p>And now <strong>the global form</strong> : </p> <pre><code>class ModelAForm extends BaseModelAForm { public function configure() { unset($this['created_at'], $this['model_d_id']); $subForm = new ModelBCollectionForm(null, array('model_a_id' =&gt; $this-&gt;getObject()-&gt;getId()) ); $this-&gt;embedForm('allmodelb', $subForm); } } </code></pre> <p>The template just shows the form simply.<br> So the first action shows the form, with with existing entries of the table, and then when you submit the form, here is the code : </p> <pre><code>public function executeCreate(sfWebRequest $request) { $this-&gt;forward404Unless($request-&gt;isMethod(sfRequest::POST) || $request-&gt;isMethod(sfRequest::PUT)); $this-&gt;form = new ModelAForm(); var_dump($request-&gt;getParameter($this-&gt;form-&gt;getName())); $this-&gt;form-&gt;bind($request-&gt;getParameter($this-&gt;form-&gt;getName())); foreach($this-&gt;form-&gt;getErrorSchema()-&gt;getErrors() as $key =&gt; $error) { echo '&lt;p&gt;' . $key . ': ' . $error . '&lt;/p&gt;'; } var_dump($this-&gt;form-&gt;getValues()); } </code></pre> <p>The first <code>var_dump()</code> shows a complete array with good datas. The second one is empty.<br> I'm working on it for hours but I don't succeed <strong>to bind the form with POST datas</strong>. </p> <p>Thanks for your help !</p> <p>Edit : I tried to override bind methods, but it didn't work... Except if I unset ModelB datas, but then the <code>save()</code> method will do an INSERT instead of UPDATE.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload