November 8, 201214 yr 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!!
November 8, 201214 yr 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
November 8, 201214 yr 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??
November 8, 201214 yr Could you set the desired URL to a PHP variable, and then header('Location:$url');?
November 8, 201214 yr 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.
November 8, 201214 yr 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
November 8, 201214 yr 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 November 8, 201214 yr by Lyndsey
November 8, 201214 yr 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
November 8, 201214 yr 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