Friend, the most correct way to do PHP would be by setting the value of the input as a Array
.
That is. Instead of doing this:
var add = 1;
function add_fields() {
var d = document.getElementById("content");
add++;
d.innerHTML += "<br /><label class='tooltips'>A ser excluído "+add+": <input type='text' name='solicitacao"+add+"'/></label>";
}
You should do this:
var add = 1;
function add_fields() {
var d = document.getElementById("content");
add++;
d.innerHTML += "<br /><label class='tooltips'>A ser excluído "+add+": <input type='text' name='solicitacao[]'/></label>";
}
Simply put: we replace "solicitacao" + add
with "solicitacao[]"
.
When doing this, PHP will access the value of solicitacao[]
through $_POST['solicitacao']
, and this will return a Array
with all the entered data.
In this way, this operation becomes more dynamic, without the use of counters to do it.
Remembering that these inputs must be declared inside the form ( <form>
), in order to send the submission of values.