Reputation: 1719
I'm using a CRUD generated _form.php in the Yii framework and want to allow the user to add additional form fields to the form at the click of a button/link without the user needing to refresh the page. So for example,
<input name="upload[]" id="upload" type="file" />
With a button that would add the same html again and again every time the button is pressed. The result would then be passed back as an array.
Really would appreciate any help here or pointers to good tutorials. Very new to Yii and the correct way of handling things.
Thanks
Upvotes: 1
Views: 2634
Reputation: 412
See this example on collecting tabular input. The controller action will show you how to process the form inputs, and you can use jquery or similar to modify the form client-side: http://www.yiiframework.com/doc/guide/1.1/en/form.table
I used a similar method to collect "child" rows. For the parent/child relationship, there is also the multimodel form extension that facilitates this pattern, but it does not work with autocomplete fields, so I stuck with the method outlined above, and do all form modifications using the JAppendo extension.
MultiModel Form: http://www.yiiframework.com/extension/multimodelform
JAppendo: http://www.yiiframework.com/extension/jappendo
Upvotes: 2