I created a form that consists of an amount of similar areas. Those areas can be added using jQuery. Each area equals one workstep used to asemble a product and therefore it has the same input-fields (description, duration,...). Here is the code (it is simplified to two hard-coded areas):
<html>
<head>
</head>
<body>
<form action="insertNewProduct.php" method="post">
<fieldset id="product-fieldset">
<legend>Produkt</legend>
<div id="step-container">
<input type="hidden" name="step[]" />
<div id="step-table" class="product-table">
<table id="basis-table">
<!-- STEP-BASISDATEN -->
<thead id="step-basis">
<!-- Basisdaten Schritt -->
<tr>
<th class="data-title">Arbeitsschritt</th>
</tr>
<tr>
<th>Bezeichnung:</th>
<td><input type="text" name="step[0][stepDescr]"></td>
</tr>
<tr>
<th>Dauer:</th>
<td><input type="text" name="step[0][stepDur]"></td>
</tr>
</thead>
</table>
</div>
<div id="step-table" class="product-table">
<table id="basis-table">
<!-- STEP-BASISDATEN -->
<thead id="step-basis">
<!-- Basisdaten Schritt -->
<tr>
<th class="data-title">Arbeitsschritt</th>
</tr>
<tr>
<th>Bezeichnung:</th>
<td><input type="text" name="step[1][stepDescr]"></td>
</tr>
<tr>
<th>Dauer:</th>
<td><input type="text" name="step[1][stepDur]"></td>
</tr>
</thead>
</table>
</div>
</div>
</fieldset>
<input type="submit" id="sendForm" value="Send"><input type="reset" id="resetForm" value="Reset">
</form>
</body>
</html>
As you can see, I added numbers to the steps
name="step[0][stepDescr]"
and therefore I get the desired result:
Array
(
[step] => Array
(
[0] => Array
(
[stepDescr] =>
[stepDur] =>
)
[1] => Array
(
[stepDescr] =>
[stepDur] =>
)
)
)
If I don't use the numbers my array becomes of course unusable:
Array
(
[step] => Array
(
[0] =>
[1] => Array
(
[stepDescr] =>
)
[2] => Array
(
[stepDur] =>
)
[3] => Array
(
[stepDescr] =>
)
[4] => Array
(
[stepDur] =>
)
)
)
How can I add these numbers (based on the amount of steps) to my HTML-Code (!) using jQuery?
for()orforeach()loop in php and print this.