I have a form where I added a group of check boxes like below:
<form action="next.php" method="get">
<input name="c1" value="1" type="checkbox">
<input name="c1" value="2" type="checkbox">
<input name="c1" value="3" type="checkbox">
<input name="c1" value="4" type="checkbox">
...
</form>
If I select the first and the 3rd check box, the URL looks good when I press the submit button, like
?c1=1&c1=3 [...]
but the $_GET array holds only the last value of c1. I know I could use the [] notation to get an array, but then the link looks like
?c1[]=1&c1[]=3 [...]
I saw sites that generate the URL without the [] and still manage to take all values into account. How do they do that ?
Thank you !
PHP requires you to use a pseudo-array notation if you want to use the same fieldname for multiple different form elements:
The
[]tells PHP to treatc1as an array, and keep all of the submitted values. Without[], PHP will simply overwrite each previous c1 value with the new one, until the form’s done processing.Sites which don’t use the
[]notation do the form processing themselves, retrieving the query string from$_SERVER['QUERY_STRING']and then parse it themselves.