Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Checkox values into URL string

Featured Replies

Hi all,

 

I have a site which I need to update via some checkboxes - so the idea being that when you select 2 checkboxes and hit submit, the url it navigates to is:

 

www.mysite.com/checkbox=value1,value2&othervariable=this

 

My html is like this:

 

<input type="checkbox" name="checky[]" value="value1" />
<input type="checkbox" name="checky[]" value="value2" />
<input type="checkbox" name="checky[]" value="value3" />
<input type="checkbox" name="checky[]" value="value4" />
<input type="checkbox" name="checky[]" value="value5" />

 

But my URL does this: www.mysite.com/checkbox%5B%5D=value1&checkbox%5B%5D=value2

 

and so on... what I am doing wrong? Why won't the values just go into the same string/variable?

 

Help!!

The %5B and %5D are actually [ and ]. They represent the fact that the values are an array. Values are not separated by a comma in URLs which is why they don't come out as you expect

  • Author

Hi Jay, thanks for that mate - I think more the issue is that it is spitting out multiple 'checky' in the string - I need it to display like:

 

www.mysite.com/checkbox=value1,value2&othervariable=this

 

Change the comma for whatever else it needs to be basically... does that make sense??

Could you set the desired URL to a PHP variable, and then header('Location:$url');?

You should just be able to name the checkbox as 'checky' without the brackets so that when the form is submitted, the values are passed through as ... checky=value1&checky=value2 etc. Then you'd request the checky object server side and split it up to perform a loop of the values.

 

Hope I made sense.

Lyndsey: That's not going to work I'm afraid, it would simply assign one value (the last one I think) of the checky params to $_GET['checky']

 

Rob: The only way you could do what you want is to capture the form submit via JS/jQuery and manipulate it to work as you want, then redirect using the window.location value

Lyndsey: That's not going to work I'm afraid, it would simply assign one value (the last one I think) of the checky params to $_GET['checky']

 

Rob: The only way you could do what you want is to capture the form submit via JS/jQuery and manipulate it to work as you want, then redirect using the window.location value

 

That's where the split and loop comes in. You'd have to request the element, split up the comma separated values (e.g. 1,2,3) then create a for each loop to do whatever you want with the values... This has always worked for me.

 

Maybe it's an ASP thing...

Edited by Lyndsey

If it's submitted as rob wants it with commas between them, you can split them then in PHP, but before that you have to get them into the CSV format which you can't do by just removing the [] from the variable names. Example, as you've said with all the checkboxes set without the [ ]

 

jaygilford.com/blahblah.php

 

You'll notice that no matter how much you submit more than one, even with them in the query string, only the last one gets submitted and used in $_GET

If it's submitted as rob wants it with commas between them, you can split them then in PHP, but before that you have to get them into the CSV format which you can't do by just removing the [] from the variable names. Example, as you've said with all the checkboxes set without the [ ]

 

jaygilford.com/blahblah.php

 

You'll notice that no matter how much you submit more than one, even with them in the query string, only the last one gets submitted and used in $_GET

 

I got you! Thanks for the clarification.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.