Hello There,
Was working on a project that is on zend framework. The task involves having having javascript generated input boxes and passing those to the controller.
I have done that before using some other mechanism but they were not somehow natural ways to do it.
It can be done in a much easier way -NATURALLY- though
lets assume your form has javascript powered email address adding inputboxes. There would be some link you would hit as add emails and it will create input boxes for you..
1. have the input box in your zend form as
$this->addElement('text', 'emails', array(
'label' => 'Emails',
'isArray' => TRUE,
'name' => 'emails[]'
));
Or however you are creating the inputbox – or anyother input
2. Then in the javascript where you are creating the input, use the same name as the element’s name
var new_email = document.createElement('input');
new_email.name = 'emails[]';
new_email.type = 'text';
new_email.setAttribute('size', 30);
3. yes, you are done!. When the form is submitted, the element with name emails[] would be passed along with the other form elements.
In your controller you would have an array of emails[] and the rest is …
Happy zenjsing