trullallero trullallero - 3 years ago 81
jQuery Question

Submit a dynamic table form through AJAX and get relatives values into PHP

I have a table form like this:

<table class="table table-striped table-bordered table-condensed">
<tr><td><input type="text" class="input-small" name="article" /></td>
<select name="colore">
<option value="nabuk">Nabuk</option>
<option value="nero">Nero</option>
<option value="blu">Blu</option>
<option value="rosso">Rosso</option>
<select name="fondo">
<option value="gomma">Gomma</option>
<option value="cuoio">Cuoio</option>
<option value="legno">Legno</option>
<select name="numero">
<option value="36">36</option>
<option value="37">37</option>
<option value="38">38</option>
<option value="39">39</option>
<td><input type="number" class="input-mini" min="1" max="200" name="qnt" step="1" /></td>

The user can add many rows to this table with a Jquery script. This script is OK and work properly.
After that, the table form is submitted through an Ajax post call to a PHP page with the
function of Jquery.

The problem is: how can I retrieve the values of each field of rows to the server side (PHP), without using hidden supplementary field (for example that submits the number of row in the table) or without use a progressive index for the name of the rows fields?

I haven't found something that explains the solution... :|

the next step of this script is passing the values of the table to the PHP with JSON object... but it's a secondary problem :)

Answer Source

You can use an array. Name your fields with [] at the end of them. For example,

<select name="colore[]">
<select name="fondo[]">
<select name="numero[]">

PHP will automatically update the indices as

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download