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? Link to comment https://forums.phpfreaks.com/topic/81121-solved-redirect-after-form-submit/ 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; ?> Link to comment https://forums.phpfreaks.com/topic/81121-solved-redirect-after-form-submit/#findComment-411645 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 Link to comment https://forums.phpfreaks.com/topic/81121-solved-redirect-after-form-submit/#findComment-411647 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..."; } ?> Link to comment https://forums.phpfreaks.com/topic/81121-solved-redirect-after-form-submit/#findComment-411669 Share on other sites More sharing options...
mediabob Posted December 11, 2007 Author Share Posted December 11, 2007 Works perfect thanks Link to comment https://forums.phpfreaks.com/topic/81121-solved-redirect-after-form-submit/#findComment-411672 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.