I have an HTML Form that contains 20 sets of fields. Here are 2 for an example:
<input type="text" class="auto-clear" id="p1weight" name="p1weight" value="" />
<input type="text" class="auto-clear" id="p1length" name="p1length" value="" />
<input type="text" class="auto-clear" id="p1width" name="p1width" value="" />
<input type="text" class="auto-clear" id="p1height" name="p1height" value="" />
<input type="text" class="auto-clear" id="p2weight" name="p2weight" value="" />
<input type="text" class="auto-clear" id="p2length" name="p2length" value="" />
<input type="text" class="auto-clear" id="p2width" name="p2width" value="" />
<input type="text" class="auto-clear" id="p2height" name="p2height" value="" />
I am using the following PHP code to generate a string ($all) to store the field values:
foreach( range( 1, 20) as $i)
{
// Create an array that stores all of the values for the current number
$values = array(
'p' . $i . 'weight' => $_POST['p' . $i . 'weight'],
'p' . $i . 'length' => $_POST['p' . $i . 'length'],
'p' . $i . 'width' => $_POST['p' . $i . 'width'],
'p' . $i . 'height' => $_POST['p' . $i . 'height']
);
$all .= implode( '|', $values) . "\n\n";
}
If my input for the 2 sets of fields is 1, 2, 3 & 4, this gives my $all value as: 1|2|3|4 1|2|3|4.
However, I would like to customise this more. Ultimately, I would like my $all to be:
Item1: Weight (kg):1 Length (cm): 2 Width (cm): 3 Height (cm): 4
Item2: Weight (kg):1 Length (cm): 2 Width (cm): 3 Height (cm): 4
How do I update my PHP above to achieve this?
Many thanks for any pointers.
1 Answer