Forum Moderators: coopster
on my html form i have six checkboxes with the same name but each have different values
Code extract from html form
<code>
<input type="checkbox" name="blah" value="1">1<br />
<input type="checkbox" name="blah" value="2">2<br />
<input type="checkbox" name="blah" value="3">3<br />
<input type="checkbox" name="blah" value="4">4<br />
<input type="checkbox" name="blah" value="5">5<br />
<input type="checkbox" name="blah" value="6">6<br />
</code>
The form action goes through to php page.
Code extract from php
<code>
<?
if (!isset($blah)) $blah= array();
foreach ($blah as $value)
{
$blah_req .= "Blah: ".$value."\n";
}
?>
</code>
I need to list all the checkboxes that have been ticked in the email. Not sure if global variables have been changed in PHP 5. The problem is that the checkboxes are not listed in the email sent.
Please advise... hope this makes sense :-) Not a php guru.
Thanks in advance!
You need to change 'blah' to 'blah[]'
NOT $blah to $blah[]
;)
<input type="checkbox" name="blah" value="1">1<br />
<input type="checkbox" name="blah" value="2">2<br />
<input type="checkbox" name="blah" value="3">3<br />
<input type="checkbox" name="blah" value="4">4<br />
<input type="checkbox" name="blah" value="5">5<br />
<input type="checkbox" name="blah" value="6">6<br />
instead of name="blah", use name="blah[]" and do the same thing for all of them.
look up part 3 here for more info on html input arrays:
[zend.com...]
As far as the naming convention goes, it is perfectly legal. There was a discussion once in the Javascript Forum in regards to using square brackets as part of an HTML name attribute. If you are interested in a bit more technical detail, here it is -- [webmasterworld.com...]