So you may have an input that can have more than one value.
You can use the article from Wappler Docs to see how to create a nice interface for selecting the multiple values, which is linked to below.
You then end up with an array of values. But how do you write that array to your database, maybe along with other single dimensional data?
Let’s assume you have:
- An array to write to the database called
my_array
- A form that writes the other data to your database too
- You want to insert a row into your database for each item in the array
Following these simple (but not so obvious!) steps…
In your form:
- Create a hidden input in your form that will write all the data to your database.
Set name =my_array_list
Set Dynamic Attributes -> Value to be your array, somy_array.items
This creates a text list of your array values separated by commas, sovalue1,value2,value3
In your Server Action:
-
Create a $_POST variable called
my_array_list
. -
Insert a database Multi Insert action.
This creates a repeat loop, inside of which is a single database insert.
You want the loop to be repeated for each item in your array… which at the moment are in a comma separated text list in your$_POST.my_array_list
variable.
To do this you need to “split” yourmy_array_list
into separate items for the repeat loop to work with. -
Set the repeat “Expression” to
{{$_POST.my_array_list.split(",")}}
Rather than typing all this in, you can use the graphical interface to select themy_array_list
post variable then choose the Text- Split String function -
You can now reference your specific array value in the Database Insert action with
$value
.
Good luck!
Antony.
Last updated: