Jump to content

Set Multiple values to a query string in PHP


Stefany93

Recommended Posts

I have this form

<form action="" method="get" name="size"> Størrelse <hr><label><input type="radio" value="9" name="size" onchange="this.form.submit()">92 (2år)</label>


<label><input type="checkbox" value="147" name="size" onchange="this.form.submit()">68 (6-9 mdr.)
</label><label><input type="checkbox" value="150" name="size" onchange="this.form.submit()">86 (18-24 mdr.)</label>
<input type="checkbox" value="149" name="size" onchange="this.form.submit()">80 (12-18 mdr.)</label>
<label><input type="checkbox" value="148" name="size" onchange="this.form.submit()">74 (9-12 mdr.)</label>


</form>

I want to make it so that when the user clicks one checkbox for example size 68 and then checks size 80 I want both sizes to be in the URL query string. But every time the user clicks a new checkbox, the query string changes accordingly. Maybe with a separator like ?size=4:23 and then I will handle it with the DB stuff.

 

Please tell me how to add multiple elements in the query string with this form, thank you!

Edited by Stefany93
Link to comment
Share on other sites

you would use an array for the name attribute  - name="size[]"

 

you would also output the checked keyword for any checkbox that has already been checked, which would generally lead to using php to dynamically produce the form, rather than you hard-coding each form element.

Edited by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.