Buy Now
Sign in

How to save repeated dropdown fields?

ozkrsanchez , January 17 2020, 16:39
O
ozkrsanchez 26
January 17 2020, 16:39 #390761
Hi everyone, I have a problem.

I have a repeat area, where I have a dropdown from which you can choose two options.

How can I do to save this in the database?
estructRepeater.PNG
estructRepeaterFrontEnd.PNG
Any idea?
O
ozkrsanchez 26
January 17 2020, 20:51 #390763
This opcions are fields in the DB. So,
mer.PNG
Attachments
mer.PNG
mer.PNG
(25.93 KiB)
62 Downloads/Views
GreyHead 64
January 18 2020, 09:58 #390776
Hi ozkrsanchez,
The 'correct' way to do this is to use a secondary table and add two rows into that linked to the main table by the record ID there.
You could also use PHP to implode the two values into a single string and save that into your main table.
Bob
ChronoForms technical support
If you'd like to buy me a coffee or two, thank you very much
healyhatman 8
January 20 2020, 22:38 #390817
You need to either save it in its own table with the foreign key linked to the ID of the main table, or save it as a JSON string in a column of your main table. {data.jsonen:model}
Your field names inside the repeater need to include a model, a key, and a fieldname. Example if you had information on products, and you were selecting the product ID and inputting how many you wanted in each row you would call the fields
product[{var:area_repeater#.key}][product_id]
product[{var:area_repeater#.key}][qty]
On submission, you would end up with a data array looking like
product =>
[0] =>
[product_id] => 1,
[qty] => 7
[1] =>
[product_id] => 4,
[qty] => 5
Then in your save data action if you were saving it as a JSON string you would use {data.jsonen:product} and it would save the array in JSON.
If you wanted it on its own table, you would first save all the other data, then inside the success of the save data action you would have an EVENT LOOP action, with the source as {data:product}. Inside it you would have a save data action for the other table, with the column data coming from {var:event_loop#.row.fieldname} and the foreign key coming from {var:save_data#.name_of_your_id_field}
Web developer at SkySpider.com.au - I DO NOT work for ChronoEngine!
Donations: paypal.me/healyhatman
Professional Work: kamron@skyspider.com.au
Custom CF / CC Plugins and Extensions: skyspider.com.au/store