tmyonline Posted August 1, 2007 Share Posted August 1, 2007 Guys: I want to direct the current page to another page once users click the form submit button. Is there a PHP function that allows me to pass in a URL for this purpose ? Many thanks! Quote Link to comment https://forums.phpfreaks.com/topic/62829-solved-how-to-direct-the-current-page-to-another-page/ Share on other sites More sharing options...
calabiyau Posted August 1, 2007 Share Posted August 1, 2007 You mean you want the form information sent to a handling script but you want the user directed a different page? Quote Link to comment https://forums.phpfreaks.com/topic/62829-solved-how-to-direct-the-current-page-to-another-page/#findComment-312768 Share on other sites More sharing options...
tmyonline Posted August 1, 2007 Author Share Posted August 1, 2007 Thanks for your prompt reply! No. What I meant is that once users click the form submit button, the current page should automatically be directed to another page that shows the users' input (because most users don't want to see the same page again with an empty form). Is there a PHP function that I can pass in a URL for this purpose ? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/62829-solved-how-to-direct-the-current-page-to-another-page/#findComment-312774 Share on other sites More sharing options...
almightyegg Posted August 1, 2007 Share Posted August 1, 2007 form.html/form.php <form action="URL.php" method="POST"> <input type="text" name="text"> <input type="Submit" name="submit"> </form> URL.php <? $text = $_POST['text']; echo "$text"; ?> That will echo what was inputted into the form field Quote Link to comment https://forums.phpfreaks.com/topic/62829-solved-how-to-direct-the-current-page-to-another-page/#findComment-312796 Share on other sites More sharing options...
l4nc3r Posted August 1, 2007 Share Posted August 1, 2007 Yeah, just remember to put the action attribute into your <form> tag. Whatever action equals is where the page is headed with the data. If you want to send data, you also need to include the method attribute. This will be GET or POST. You can google the difference. It looks like you already know how to write forms. Just make sure everything has a name attribute (which will be the index in the $_POST or $_GET array in the next page.) Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/62829-solved-how-to-direct-the-current-page-to-another-page/#findComment-312809 Share on other sites More sharing options...
tmyonline Posted August 1, 2007 Author Share Posted August 1, 2007 But my "action" attribute already contains the link of the current page, the page from which the data is read (and write to the database). In fact, I have set: action="some_other_link" and yes, it worked, it did direct the current page to the specified page. However, in doing so, it fails to record the values that users enter. Any other alternative? Quote Link to comment https://forums.phpfreaks.com/topic/62829-solved-how-to-direct-the-current-page-to-another-page/#findComment-312816 Share on other sites More sharing options...
calabiyau Posted August 1, 2007 Share Posted August 1, 2007 Without seeing all your code, I assume you are posting the fields back to the same page and you have an if clause that checks to see if the form was submitted and puts it into the database? And now you want to send them to another page after the info is inserted? If that is the case, after you do your inserts, you can use the header function to send them somewhere else...BUT, you will have to move all that part of the code to the beginning of the file to avoid headers already sent errors. header("Location: http://yourdomain.com/yourredirect.php"); Quote Link to comment https://forums.phpfreaks.com/topic/62829-solved-how-to-direct-the-current-page-to-another-page/#findComment-312824 Share on other sites More sharing options...
tmyonline Posted August 1, 2007 Author Share Posted August 1, 2007 Yeah, that's what I'm talking about. Actually, before posting for help on this forum, I had found this header function in my PHP reference book but I was skeptical about it since I wanted to direct the whole page, not just the header. Now, since you "calabiyau" suggested this header function again, I went ahead and tried and yes, it worked successfully. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/62829-solved-how-to-direct-the-current-page-to-another-page/#findComment-312833 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.