POST checkbox group
Hi
Trying to send the data from a checkbox group to a php process and it's
just sending the last box clicked as a variable, rather than the whole
group as an array. Am I being stupid?
ie html:
<form name="selectform" action="data.php" method="post">
<input name="days" type="checkbox" value="mon" />Mon
<input name="days" type="checkbox" value="tue" />Tue
<input name="days" type="checkbox" value="wed" />Wed
<input type="submit" name="Submit" value="Submit" />
</form>
php:
print_r($_POST["days"])
gives
Array ( [days] => tue [Submit] => Submit )
even when Mon and Tues are checked
Thanks
--
Richard
Re: POST checkbox group
..oO(Richard Walker)
>Trying to send the data from a checkbox group to a php process and it's
>just sending the last box clicked as a variable, rather than the whole
>group as an array. Am I being stupid?
>
>ie html:
>
> <form name="selectform" action="data.php" method="post">
> <input name="days" type="checkbox" value="mon" />Mon
> <input name="days" type="checkbox" value="tue" />Tue
> <input name="days" type="checkbox" value="wed" />Wed
> <input type="submit" name="Submit" value="Submit" />
> </form>
Use name="days[]". Then $_POST['days'] will be an array, containing the
values of all checked checkboxes.
Micha
Re: POST checkbox group
Many Thanks. Easy when you know how!
--
Richard
Michael Fesser wrote:
> .oO(Richard Walker)
>
>> Trying to send the data from a checkbox group to a php process and it's
>> just sending the last box clicked as a variable, rather than the whole
>> group as an array. Am I being stupid?
>>
>> ie html:
>>
>> <form name="selectform" action="data.php" method="post">
>> <input name="days" type="checkbox" value="mon" />Mon
>> <input name="days" type="checkbox" value="tue" />Tue
>> <input name="days" type="checkbox" value="wed" />Wed
>> <input type="submit" name="Submit" value="Submit" />
>> </form>
>
> Use name="days[]". Then $_POST['days'] will be an array, containing the
> values of all checked checkboxes.
>
> Micha
Re: POST checkbox group
..oO(Richard Walker)
> Many Thanks. Easy when you know how!
It's in the manual, but a bit hidden:
3. How do I create arrays in a HTML <form>?
http://www.php.net/manual/en/faq.html.php#faq.html.arrays
4. How do I get all the results from a select multiple HTML tag?
http://www.php.net/manual/en/faq.html.php#faq.html.select-mu ltiple
Micha