hmdnawaz Posted January 8, 2011 Share Posted January 8, 2011 I have two pages. one is insert_events.php and the other is veiw_events. In insert_events i have a form which have a submit button. I want when i click on the submit button, it redirects me to the view_events.php page showing the events. Any idea about this problem will be appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/223745-how-to-redirect-to-another-page-on-the-submit-button-of-the-form/ Share on other sites More sharing options...
jcbones Posted January 8, 2011 Share Posted January 8, 2011 You could put the name of the page in the `action` attribute of the form element tag. Quote Link to comment https://forums.phpfreaks.com/topic/223745-how-to-redirect-to-another-page-on-the-submit-button-of-the-form/#findComment-1156552 Share on other sites More sharing options...
hmdnawaz Posted January 8, 2011 Author Share Posted January 8, 2011 when i write the page name in the action attribute of the form then problem creates in updating the form. Any alternative approach?? Quote Link to comment https://forums.phpfreaks.com/topic/223745-how-to-redirect-to-another-page-on-the-submit-button-of-the-form/#findComment-1156565 Share on other sites More sharing options...
QuickOldCar Posted January 8, 2011 Share Posted January 8, 2011 If you place view_events.php in the action of the submit form it then doesn't work? Maybe you need to rewrite the code so it does. Post both files in code so everyone can see what's going on. Quote Link to comment https://forums.phpfreaks.com/topic/223745-how-to-redirect-to-another-page-on-the-submit-button-of-the-form/#findComment-1156574 Share on other sites More sharing options...
gizmola Posted January 8, 2011 Share Posted January 8, 2011 One typical way of handling this is to have your insert_events.php form action point to itself. The best way is probably to do a basename(__FILE__) call. You should have some code that checks state at the top, to insure that the method is POST and that any required columns are filled in correctly. If all the criteria is met, then you do whatever is required to actually insert the data. If all goes well, then do a simple header('location:...') call to your view_events.php script. The important thing is that you can not call header if you've output anything, so as long as your script does not echo anything, you'll be able to call header and redirect at any point. It is very important that immediately after the header() call you exit the script! Many people have neglected to code for this, and people trying to exploit your site will use tools that for example, will not honor the redirect (since it's a client side activity) and it's possible that your code can progress past the redirect into an area that you did not intend to execute. Otherwise, there is not much else to this -- very simple. In a nutshell: if (//check that the method was POST, and check for any required columns, format of data etc.) { // Do your insert code here. If all is well... header('location: view_events.php'); exit; } else { // Output form target } Quote Link to comment https://forums.phpfreaks.com/topic/223745-how-to-redirect-to-another-page-on-the-submit-button-of-the-form/#findComment-1156575 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.