I would like to have a form that can dynamically load one of many sub forms based on a user’s input.
What I’ve tried so far is having a dropDownList with some ajax that will call an action in the controller. This controller will then renderPartial the subform and the resulting code will be inserted into the current page.
The problem is, this rendered sub-form also has its own pair of form tags. This causes the data in the sub-form to be lost when the outer form is submitted.
You could also just pass the $form variable into a renderPartial. Separate your form fields from the beginWidget/endWidget into a separate partial, so then you can pull in the renderPartial at will while passing $form.
I have been trying to troubleshoot this exact problem for a while now. I am using the CHtml approach, but I am still quite new to Yii and I am not sure how we could validate and have errors show up on the ajax loaded sub-form, when the outer main form is submitted. Any thoughts ?