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
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

Link to comment
Share on other sites

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...";
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.