Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Checkbox array as a single parameter?

    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.

    Code:
    <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:
    Code:
    http://www.mysite.com/results.php?lang[/url][]=en&lang[]=fr&lang[]=es
    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:

    Code:
    http://www.mysite.com/results.php?lang[/url]=en|fr|es
    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?
    Last edited by htcilt; 02-08-2010 at 03:52 PM.

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    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 ...

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    238
    Thanks
    9
    Thanked 0 Times in 0 Posts
    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/showthre...016#post920016

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •