Forums

How to save repeated dropdown fields?

ozkrsanchez 17 Jan, 2020
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?





Any idea?
ozkrsanchez 17 Jan, 2020
This opcions are fields in the DB. So,

GreyHead 18 Jan, 2020
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
healyhatman 20 Jan, 2020
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}
This topic is locked and no more replies can be posted.