redirect, but wanna keep post variables..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bg
Forum Contributor
Posts: 157
Joined: Fri Sep 12, 2003 11:01 am

redirect, but wanna keep post variables..

Post by bg »

Im writing the form validation portion of an online store, and have run into a problem. When the user clicks the button to go onto the next "step" in the ordering process, it checks the input and if its not correct it redirects them (header("location: ...")) back to the page and spits out the errors with the input. The problem is when you redirect like this all post variables die, im wondering if anyone knows a way or workaround for this? Thanks,

-brian
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

aside form finding a way to embed the post commands in the redirect, there's no way to keep them as post.
you can change them to get.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

you could put all the values in a hidden form, then use javascript to automatically submit the form using POST.

Mark
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post by Unipus »

That or make them session variables.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Or us the URI...

Code: Select all

$array = array("foo"=>"bar", "bar"=>"mofo");
$tmp = serialize($array);
header("Location: next.php?info=".$tmp);

// then on next.php, unserialize, and do whatever...
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Sessions.
User avatar
PixelMaster
Forum Newbie
Posts: 11
Joined: Sat Aug 16, 2003 11:48 am

Post by PixelMaster »

Or use serialize(), convert the resulting string to base64 with base64_encode(), add it to your URL, and then base64_decode() and unserialize() it on the other end ... you can preserve anything but resource handles this way... only downer is that you end up with a big, long, ugly URL.
Post Reply