-2

I'm new to PHP. I want to send data from one page to another page by post.

if(isset($_REQUEST['submit']))
{

header("location:nextpage.php");
//here i want to send data coming from my text box's by post function
}
AMIC MING
  • 6,306
  • 6
  • 46
  • 62
  • http://stackoverflow.com/a/4939261/362536 Also, use full URLs with your `Location:` headers. – Brad Feb 02 '13 at 00:04
  • Your prerequisite won't work. Redirects will always use GET. You either need a `
    ` with `method=POST`, or a server-side request (= no redirect in the browser) using a HTTP lib.
    – mario Feb 02 '13 at 00:04
  • @mario, That is not entirely true. It isn't specified what the browser should do when directing with POST data. But yes, the behavior cannot be guaranteed. – Brad Feb 02 '13 at 00:05
  • if i use form with post method then how do i check for validations like require field validations – Yogesh Yadav Feb 02 '13 at 00:25

1 Answers1

2

You should just target the right page to begin with.

<form action="your-processing-script.php" method="post">

Keep in mind the action is relative, so depending on your file structure, you may want a slash before the file url to prevent confusion.

/your-processing-script.php
Kai Qing
  • 18,793
  • 5
  • 39
  • 57
  • +1 for keeping it simple. curl or header("Location: ...") is no match for the good old refer-to-the-right-page-directly-trick – Simon Forsberg Feb 02 '13 at 00:08
  • thank you but i have to check some validations before posting the data like required field validate – Yogesh Yadav Feb 02 '13 at 00:14
  • if i use this in directly in form then i will not be able to check some validations before posting the data like required field validate – Yogesh Yadav Feb 02 '13 at 00:21
  • You can do validation on your target and pass back to the form page with header. You can set posted values in session to re-populate the form, etc. there are many ways to go about doing this – Kai Qing Feb 02 '13 at 00:32
  • yes i know the other ways but here i just want to know "is that possible to use post function with header() " – Yogesh Yadav Feb 02 '13 at 00:40
  • not while maintaining the values of $_POST unless you use a medium to transfer and re-populate, which is not advised. header is a redirect page load knowing nothing except the parameter you pass it. You would need to store the values of post in a temp table, session, or other means to relay the info. But in that you can expose risk depending on the values you try to pass openly. I think the real question is what is your file structure that calls for an action like this. Normally you validate, then call a method to process or reload the form on error. – Kai Qing Feb 02 '13 at 01:14