Add new inputField with ajax/jQuery

Hi,

I have a form which contains a various number of drop down fields, input text fields and such.

Now I’d like to extend this static form. If the user clicks on the “add form” link then I’d like to have the form rendered again and appended to the existing one.

Now I know that I can use jQuery to append text fields and such to the existing form without a problem. What I want to accomplish seems a little more complicated.

I wrote an ajax call to partially render the form so I would be able to append it to the existing one.

However this does not work since I am using activeTextFields etc. I’d now need to supply $form which I am not able to since $form does not exist anymore.

So what I am trying to achieve is to dynamically add form fields. Ideally using my existing _form view. Also, these added fields would have to be re-created if the validation fails. And in this case be re-filled with the user entered data.

How would you solve this issue?

This maybe what you are looking for? http://www.yiiframework.com/doc/guide/1.1/en/form.table

Yes, I think this would do it! Thanks! Didn’t know Yii has this functionality!

Thanks for pointing this out :)