Didn't know how to specify question to be more specific and more meaningful.
Basically I've a Customer information module with ability for adding multiple contacts for each customer and it will something like that:
<p>Contacts</p>
<ul>
<li>
<label for="name">Name: <label><input type="text" name="name[]" value="" />
<label for="lname">Last Name: <label><input type="text" name="lname[]" value="" />
<label for="phone">Phone: <label><input type="text" name="phone[]" value="" />
</li>
<li>
<label for="name">Name: <label><input type="text" name="name[]" value="" />
<label for="lname">Last Name: <label><input type="text" name="lname[]" value="" />
<label for="phone">Phone: <label><input type="text" name="phone[]" value="" />
</li>
<li>
<label for="name">Name: <label><input type="text" name="name[]" value="" />
<label for="lname">Last Name: <label><input type="text" name="lname[]" value="" />
<label for="phone">Phone: <label><input type="text" name="phone[]" value="" />
</li>
</ul>
This is a rough example to show you idea. When that form is submitted to php script, and for example last name in second contact details is blank, I'm getting offset error when I'm trying to loop through all contact like that?
<?php
$total = count($_POST['name']);
$name = $_POST['name'];
$lname = $_POST['lname'];
$phone = $_POST['phone']
for($x = 0 ; $x > $total; $x)
{
echo 'Name: '.$name[$x].' Last name: '.$lname[$x].' Phone: '.$phone[$x];
}
?>
I didn't test this particular snippet, it is here only to show you idea( probably few of you had similar issue).
$name = $_POST['name'] ? $_POST['name'] : '';or$name = $_POST['name'] == '' ? '' : $_POST['name'];issetandemptyto ensure that the item exists and that it has a value. In some cases,emptywill not work as you will want to receive 0, '', or false as a valid value. In which case you would need to apply a little more validation.