View Full Version : Checkbox array as a single parameter?

02-08-2010, 03:53 PM
Hi all,

I have a standard for sent using the $_GET method.
It contains a number of checkboxes - any combination can be ticked e.g.

<input type="checkbox" name="lang[]" value="en">English<br />
<input type="checkbox" name="lang[]" value="fr">Franšais<br />
<input type="checkbox" name="lang[]" value="es">Espa˝ol<br />

If all 3 are ticked and the form is submitted the URL shows:


I would like to sent the contents of the array as a single parameter with a separating character that will be used to explode back into an array i.e:


Although my current method does the job, the above method is a much cleaner url. Its also the method eBay use.

Does anyone know how this can be acheived?

02-08-2010, 04:18 PM
Just a few ideas:

In my opinion with checkboxes it could be done with JavaScript. You would need

- either a separate form with hidden fields. The checkboxes as well as the submit button would not belong to this form. Actually they would not belong to any form. When the button is clicked, a JavaScript would set the hidden fields of this form as necessary (e.g. to en|fr|es) and submit it.

- or you could do it without any forms at the page at all. In this case the JavaScript should form an URL according to the checkbox values and redirect to this URL using "location".

But if JavaScript is turned off in the user browser, your form would not work at all.

Or it could be done without JavaScript: you submit your data by GET as you do now (or by POST - does not matter) to some other script. There you process your data and redirect back by sending a Location header using any query string you wish. Then at the original page you use this query string to preset the values of checkboxes and other fields as necessary.

Or you could simply submit your form by POST ... In this case the URL would not contain any parameters at all. But I think this is not suitable if you are asking about GET most probably ...

02-08-2010, 04:55 PM
Thanks for the reply.

I'm using GET as I pass additional parameters to the URL such as pagination offsets... which is causing me more headaches if you've read my other recent posts lol http://www.codingforums.com/showthread.php?p=920016#post920016

I think I best tackle one issue at a time (pagination URLs) and revisit this after. But thank you for your suggestions.