Jump to content

[SOLVED] redirect after form submit


mediabob

Recommended Posts

Hi, I need help with redirecting after submitting a form. When the form submits, I would like to redirect to the master page so basically like this:

 

Page of stuff > Form to add more stuff > (after submit)Page of Stuff

 

I was trying to save the referring URL to a variable and use that to redirect back to the master page on form submit but the problem is that the form puts the info in a database so it posts to itself which changes the referring URL to the URL of the form itself.

 

Can someone help solve this problem?

Link to comment
https://forums.phpfreaks.com/topic/81121-solved-redirect-after-form-submit/
Share on other sites

I am using the header, but the problem is that my redirect URL is not static, so I need to get the refering URL to send them back, so I was saving the referring URL as a variable and using that variable in the header.

 

But when the form posts it also changes the reffering URL to the URL of the form itself

You can pass the value through hidden field and redirect it later.... for e.g.

index.php

<?php
$currpage = "index.php";
?>
<form name="a1" method="post" action="nextpage.php">
<table width="627" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="627" height="27" valign="top">
<input type="submit" name="submit" value="submit" />
<input type="hidden" name="pagename" value="<?php echo $currpage;?>"  />
</td>
</tr>
</table>
</form>

 

and in nextpage.php you can just get the value and redirect

<?php
if (isset($_POST['pagename']))
{
$page = $_POST['pagename'];
/* Redirect browser */
header("Location: {$page}"); 
/* Make sure that code below does not get executed when we redirect. */
exit;
}
else 
{
echo "Page name not set...";
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.