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!

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.