Pre-processing form data and then forwarding it on

I am sending data input from my webpage to a 3rd party.

That 3rd party has given me the HTML <form> code with method=“post” that submits to processing software on their servers. I do not have access to their processing software and they will not customise it for me.

The fields sent via the form are only type=“text” fields.

The problem I have is that I want one of those text fields to include a date and I want to be able to verify the date input so that a user does not input something stupid like 30th February.

The solution I am thinking of is as follows:

  • Create my own <form> on my HTML webpage
  • Use the method=“post” to submit the data to my own php processor that will validate the date entry
  • If all is correct, submit the data onto the 3rd party

However, I cannot find out how to do the last part - i.e. send the data on to the 3rd party as though it had come from their own HTML <form> code.

Is there a way in php to simulate the sending of data to the 3rd party processor as though it had come from a submit from their <form> code with the method=“post”.

I think there must be a simply way to do this, but I do not have an in-depth knowledge of php and I cannot work it out.

Can anyone point me in the right direct?

To make things easier, why can’t you just modify the form fields and use pulldown menus for month day and year? Those will submit as text (or integer if they allow that) so the form processor shouldn’t have anything to complain about. Plus, the user won’t be able to enter anything except what you let them, so it’s more secure as well.

If you can’t do that, ask them if they have server-side validation. If they do, then you could implement javascript validation. Then, if somebody has js disabled and enters the incorrect information their processor will spit out the error message allowing the user to fix their submission.

You can either use curl or streams to send a POST HTTP request to the other server. That’ll allow you to validate and filter all the data, then post it on in the correct format.

Stream Contexts (see comments for ideas how to send a POST request)

cURL

I always find CURL to be the best option for submitting POST variables through PHP. It is fairly easy to accomplish if you look through the PHP manual (look up curl). However below is a simple demo of how to do what you need:

Submitting a form post with PHP and CURL

Thank you all for your replys.

In particular, thank you to cranial-bore and matlib for the helpful links. After much fiddling about with my code I’ve finally got this part working - I bet you can guess, I’m very new to php :confused: