Jump to content

How to redirect to another page on the submit button of the form???


hmdnawaz

Recommended Posts

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

Link to comment
Share on other sites

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
}

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.