Page 1 of 1

passing an array using $_GET

Posted: Tue Jan 31, 2006 3:54 am
by s.dot
Hi,

I currently have a form that uses $_POST to send an array of checked (checkbox) values. My PHP script goes through each element in the array and deletes from the database.

However, I want to do it using $_GET, so my URL will look like action=deletechecked&checklist=1,2,3,4,5 etc

I tried it and it currently looks like this

Code: Select all

&action=deletechecked&checklist=360849&checklist=360841&checklist=360836&checklist=360830&checklist=360820&checklist=360808&checklist=360804&checklist=360797&checklist=360400&checklist=360379&checklist=360337&checklist=360318&checklist=360294&checklist=360290&checklist=358486
There's a &checklist=## for each element.

Would I need to use javascript to get these into a list? Or can I not do this using $_GET?

Posted: Tue Jan 31, 2006 6:10 am
by raghavan20
when GET is used with check or radio boxes, it returns the same format you have showed up...nothing to worry about still you would be able to access in the same way you did with POST.

Posted: Tue Jan 31, 2006 6:50 am
by s.dot
but I want to get them into a list like &checklist=133432,3423,4234523,42323

Posted: Tue Jan 31, 2006 7:14 am
by raghavan20

Code: Select all

<?php
if (isset($_GET["checkValues"])){
	print_r($_GET["checkValues"]);
	echo implode(",", $_GET["checkValues"]);
}

?>
<form method = 'get'>
	100<input type = 'checkbox' name = 'checkValues[]' value = '100' />
	200<input type = 'checkbox' name = 'checkValues[]' value = '200' />
	300<input type = 'checkbox' name = 'checkValues[]' value = '300' />
	400<input type = 'checkbox' name = 'checkValues[]' value = '400' />
	<input type = 'submit' name = 'submitValues' value = 'Submit' />
</form>

Posted: Tue Jan 31, 2006 7:40 am
by CoderGoblin
The obvious problem with what you are trying to do is that you want to change the way the browser works. As far as I am aware what you are asking for is only feasible if you preprocess the information with something (Javascript on the form submit as you mentioned). If this is purely for aesthetic reasons you have to ask yourself is the time/need to use javascript worth it ?

The deletion code itself could check for either possibility and react accordingly if you need to delete things by hand.

Is there any reason you wish to send the information as a GET rather than a POST ? The deletion code itself could check for either possibility and react accordingly if you need to delete things by hand.

As you are deleting things from the database I would tend to stick to POST and use header("Location") to redirect the page to clear the POST refresh information.