Click to See Complete Forum and Search --> : submit on automatic redirect, how?


buckky
12-28-2007, 10:32 PM
okay what ive got is a page using if/elseif php based on a var from the previous page to determine if and where to redirect. the redirect is not associated with the submit button, in fact they are mutually exclusive by the if/elseif. what i need to do is submit form data to the redirected pages from the previous page, or the current page(the one with the redirects). i already use another if/elseif to change the action url in the form tag. but on refresh it does not submit the posted data. im a bit stuck.. heres in essence whats going on..

<html>
<body>
<LINK REL="stylesheet" HREF="xyz.css">
<?php
$select = $_POST['select'];
$var1 = $_POST['var1'];
$var2 = $_POST['var2'];
$var3 = $_POST['var3'];
$var4 = $_POST['var4'];
if ($select == a){echo"<FORM ACTION=\"xyz1.php\" method=post>";}
elseif ($select == b) {echo"<FORM ACTION=\"xyz2.php\" method=post>";}
elseif ($select == c) {echo"<FORM ACTION=\"xyz3.php\" method=post>";}
elseif ($select == d) {echo"<FORM ACTION=\"xyz4.php\" method=post>";}
if ($select == a)
{echo"page content for dispay if select is a";}
elseif ($select == b) {echo"
<meta http-equiv=\"refresh\" content=\"0;url=http://xyz.com/xyz2.php\">
";}
elseif ($select == c) {echo"
<meta http-equiv=\"refresh\" content=\"0;url=http://xyz.com/xyz3.php\">
";}
elseif ($select == d) {echo"
<meta http-equiv=\"refresh\" content=\"0;url=http://xyz.com/xyz4.php\">
";}
?>
<input type=hidden name="var1" value="<?php echo $var1;?>">
<input type=hidden name="var2" value="<?php echo $var2;?>">
<input type=hidden name="var3" value="<?php echo $var3;?>">
<input type=hidden name="var4" value="<?php echo $var4;?>">
</form>
</body>
</html>

as you can see what i dont know how to do is cause the form information to submit to the pages that the user is redirected to. and no i dont want them to see this page at all unless "select" value is a.

BrettNooyen
01-02-2008, 10:53 AM
Just curious, is there a reason you are using a <meta refresh instead of a typical php redirect?

header("Location: xyz.php"); ?

TJ111
01-02-2008, 12:14 PM
Because he is outputting data (HTML) before the redirect. If you output anything from the script, the HTTP headers are already sent and you can't use header redirects. Although since the redirect is instant, there is really no reason to output HTML.

As to the OP's problem, post data only exists on the page where the information was submitted too. An easy thing to do would be just save the $_POST data as $_SESSION variables.

buckky
01-02-2008, 01:31 PM
ya i know my stuff is screwy. i didnt use php redirect out of simple ignorance. i wound up doing a big workaround by shifting the form outputs to the next page after the redirects(aside from the data that guides the redirects to the right pages). this is my first project with html forms and php, i knew none of either before i started. i only really know what im tring to do, and i throw code at it till it does that.
btw i know this is going to come up again, and i didnt find an example of what i needed to do, so any links or more code would be fantastic. again as you can see above it needs to redirect based on data from the previous page, to more than one possible url, display the normal page content
if no redirect is called for, and pass data to the new or next page.
ill google $_SESSION variables and php redirect. i tried to find the php redirect, but i didnt find a clear enough example. i know, dont laugh but all i could find was java and stuff.
thanks for the response and for helping a total noob.

edit- im looking for examples that use only html and php thanks.

TJ111
01-02-2008, 01:48 PM
it's pretty simple to use sessions.

session_start() //call this on every script where you need access to the $_SESSION superglobal
$_SESSION['var1'] = $_POST['var1']
$_SESSION['var2'] = $_POST['var2']

//or if you have alot of $_POST values
foreach($_POST as $k => $v) {
$_SESSION[$k] = $v;
}

//then just call your switches
//(you can't use header redirects after calling session_start() )
switch($_POST['select']) {
case "a":
//you didn't have a url for a
break;
case "b":
echo "<meta http-equiv=\"refresh\" content=\"0;url=http://xyz.com/xyz2.php\">";
break;
}


Then you can access all those $_SESSION variables on any page on your site (as long as you call session_start()). The $_SESSION variables will exist until either the user closes their browser or the session expires.

Edit:
You can also get rid of $_SESSION variables by calling one of the following:

session_unset() //clears all $_SESSION variables
session_destroy() //destroys the session