1
I have a form that will add links from download servers to a file, however each file may contain n links from download servers
In HTML:
<input type="text" name="server_down">
This input is cloned by a jQuery so that the user can add other server options if the file has more than one distribution server, so I did something like this:
<input type="text" name="server_down_1">
<input type="text" name="server_down_2">
<input type="text" name="server_down_n">
Whenever the user clones the input, the last value adds up to 1. However, to send to the database I need to make a loop based on the amount of elements I cloned, and for this I made an auxiliary input as follows
<input type="hidden" name="field_clonada" value="Quantas vezes foi clonada">
This way I can save in the database without problem, but what I would like to know is if there are more "efficient" ways to do this, or what are the other ways to do it?
The PHP Loop I use to process the data is this:
<?php $count = $_POST['field_clonada'];
for ($i=1; $i <= $count; $i++) {
salva_no_bd($arq_id, 'server_down_'.$i, $_POST['server_down_'.$i]);
}
Just do
name="server_down[]"
, with brackets and in PHP do$_POST['server_dow']
to obtain the array.– Woss