Forums

Storing data from dynamic forms

csilib 11 Jan, 2010
Hi. I needed a form that would allow users to dynamically add fields so I've adapted this jquery solution http://sroucheray.org/blog/demos/jquery-dynamic-form. The form itself works great but I can't seem to figure out how to properly save the data to a database table. I know next to nothing about java but I'm guessing the problem has to do with the field names being dynamically generated. If anyone can offer a solution, I'd be extremely grateful. Thanks for your time.

joe
GreyHead 11 Jan, 2010
Hi joe,

Hmmm . . . if you know what the input names will be you can add them into the database table manually. Hard to say any more without seeing what the code actually produces.

Bob

PS JQuery may well cause problems with other ChronoForms features unless you set it into no-conflict mode.
csilib 12 Jan, 2010
Hi Bob. Thanks for the quick response. The example I'm using from that page is #duplicate3 (Multiple fields duplication). The form allows the user to enter their first and last name followed by their address. Then, it allows them to add another set of address fields to enter multiple addresses. Interestingly, the javascript assigns new input ids for each new set, but the input names remain the same.

In other words, the first set of input ids are:
address0
postal1
city2

The ids for the duplicated set are:
address3
postal4
city5

The input names, however, are all the same:
adr[]
postal_code[]
ville[]

Based on what you've said it seems the solution would be: 1) edit the javascript file <http://sroucheray.org/demo/jquery-dynamic-form/jquery-dynamic-form.js> to ensure that all dynamically generated fields are assigned unique names; then 2) add the names to the database table manually.

Is this correct?
supermau 12 Jan, 2010
Hi joe, I found your post and have been trying to make jquery work in my form without success. Could you be so kind to attach the javascript you used to get the form working? Thanks in advance.
GreyHead 12 Jan, 2010
Hi Joe,

The array names like adr[] should work OK.

You'll need to have ChronoForms set to handle arrays for you and you should probably make sure that the first address block is visible in the Form HTML so that ChronoForms knows that the arrays exist.

Bob
This topic is locked and no more replies can be posted.