Dynamically add CForm and Save Multiple Records

I am curious to know if there is a way to dynamically add an arbitrary number of CForms as SubForms.

I’m not going to try and describe this entirely in abstract terms so I will simple provide an example.

Customers can have an arbitrary number of addresses linked to their account, so if they wanted to add two when they register I don’t see why I should prevent that. I show them a form where they can put in their First and Last name and Jquery tabs beneath that with one tab being an Addresses tab. On that tab there is a button they click to add an address and when that happens it adds an Address Form as many times as they click it.

So with that being the example,

How could I display multiple forms by clicking the add button and be able to process that in the controller with something like

foreach($_POST[‘Address’] as $address) {

//logic to save one address here.

}

Thanks for any help/suggestions

Maybe this part of the Definite Guide could help you out? You have, in a sense, tabular input here.

Dear Friend,

The situation here is one user and many addresses.

Then we have to create 2 tables.

1.User.

2.Address.

The situation becomes very similar to one Post and many comments..

An article is followed by comments associated with that article and then followed by a comment form

to make further comments.

Have a look at blog tutorial to achieve that.

Regards.

Thank you for the suggestions.

I think I got it figured out.

If you succeed with this problem can you provide your code, please?

Thank you.

I did find a way to do it, but I had to extend the framework almost to the point of my code becoming a ‘hack’. So I eventually ended up back at using the code from the blog post example for adding comments. I have not fully implemented this yet but once I do I will share it. This is a website I am working on part time so it will take a week or two to get back with anything complete.