samedi 28 février 2015

Symfony2, submitting form with additional dynamically created fields

I am using Symfony2 to submit some form data. I want to submit my form but I am creating some dynamic form elements and it is not working which is understandable.


Here is my form builder:



$builder->add('email','email',
array(
'attr'=>array(
'class'=>'form-control'
),
)
);


On my page I am creating additional fields with the name 'name="additionalEmails[]"'. There can be several of these fields because I want the user to be able to add multiple emails.


Now of course my form is not working because this element is not in the form builder, so on submission this "$form->isValid()" == false and the submission fails.


How can I add these form elements and actually get my form to have $form->isValid() == true?


Thanks.


Aucun commentaire:

Enregistrer un commentaire