mediabob Posted December 11, 2007 Share Posted December 11, 2007 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? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 11, 2007 Share Posted December 11, 2007 you can use header to redirect http://php.net/header <?php header("Location: index.php"); /* Redirect browser */ /* Make sure that code below does not get executed when we redirect. */ exit; ?> Quote Link to comment Share on other sites More sharing options...
mediabob Posted December 11, 2007 Author Share Posted December 11, 2007 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 Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 11, 2007 Share Posted December 11, 2007 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..."; } ?> Quote Link to comment Share on other sites More sharing options...
mediabob Posted December 11, 2007 Author Share Posted December 11, 2007 Works perfect thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.