Last Updated: February 25, 2016
· tmaindron

Symfony 1.4 duplicating input hidden on embedded forms

The problem:

When rendering a form with embedded sub forms in Symfony 1.2 (or higher), you'll end up with symfony including twice the hidden fields of the embedded form if you call all the renderHiddenFields() methods.

For exemple:

<!-- viewSuccess.php -->

<!-- ... render some fields of the form ... -->
<?php echo $form['username'] ?>

<!-- render the hidden fields of the embedded form -->
<?php echo $form['EmbeddedForm']->renderHiddenFields() ?>

<!-- Now render the main form hidden fields -->
<?php echo $form->renderHiddenFields() ?>

If $form['EmbeddedForm'] contains hidden fields (ie sfWidgetFormInputHidden) they'll be rendered twice.

How to fix:

To prevent this, you can call $form->renderHiddenFields(false) on the main form. It will disable recursion into subforms.