passing an array using $_GET

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

passing an array using $_GET

Post 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?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

but I want to get them into a list like &checklist=133432,3423,4234523,42323
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post 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>
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
Post Reply