Page 1 of 1

Check input after form submission, then continue with POST

Posted: Tue Jul 26, 2011 12:17 pm
by boshank20
Hi,

I am hoping to create a form which collects users details, checks if the details are valid and then posts to a third party payment system. The issue I am having is that if the form submits back to the same page in order to do the validation, then I have no way of sending a redirect with the POST headers still intact.

My way of getting around this at present is to have the form (on formPage.php) submit back to itself, and if the details are valid then to redirect to another page on my site (confirmDetails.php). On this second page the user must check their details and click on a confirm button which then does the POST to the third party.

Is there any way to have the form post back to the same page in order to validate the users details, and then to programmatically post to the third party? My understanding is that modifying the header location will not work as the post variables with not remain intact. I have seen a number of forum posts where it is suggested that javascript be used to automatically submit the form, but I would like to avoid this if possible, in case the user has javascript disabled.

Thanks for your help

Re: Check input after form submission, then continue with PO

Posted: Tue Jul 26, 2011 2:37 pm
by AbraCadaver
You can use http_post_data() or http_post_fields() but since PHP is server side then it will not redirect the user. You would need to use a javascript post or do it the way you are now as the client needs to post in order for the browser location to change.

Re: Check input after form submission, then continue with PO

Posted: Tue Jul 26, 2011 4:19 pm
by flying_circus
Wouldn't this be a good case to use curl? Unless I am not completely understanding, can't you use curl as basically a proxy and then redirect the user based on the response?

Re: Check input after form submission, then continue with PO

Posted: Wed Jul 27, 2011 4:29 am
by boshank20
Thanks for the quick response.

As far as I understand curl would not work as the user must be sent to the third party site with the correct post data. If I were to simply redirect them the third party site would give some error page as the correct authentication data would not be in the post headers

Re: Check input after form submission, then continue with PO

Posted: Wed Jul 27, 2011 7:49 am
by AbraCadaver
boshank20 wrote:Thanks for the quick response.

As far as I understand curl would not work as the user must be sent to the third party site with the correct post data. If I were to simply redirect them the third party site would give some error page as the correct authentication data would not be in the post headers
Correct. So you need JS or do it the way you do now.

Re: Check input after form submission, then continue with PO

Posted: Wed Jul 27, 2011 11:37 am
by boshank20
Ok. Thanks for your help