Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I use a 3rd party form processor. The issue is, I need a way to redirect the user after submitting data to the 3rd party form processor.

I was thinking of: 1. Client submits form 2. My php form-processor captures the data 3. My php form-processor then Submits the data via POST or GET to the 3rd party form processor 4. My php form-processor then redirects the user to a thank you page.

I might be over thinking this, but the only way I see of doing this is making a form that posts data that has been posted to it. Otherwise the form will just send my user to the 3rd party processor without redirecting them to whatever page I choose. The 3rd party form processor doesn't have a way of me using custom redirects.

share|improve this question
with this scheme, you may not have a way to know if the information was successfully submitted to the 3rd party form processor. Also, if you have some sample code/test page for this then that would be helpful. – Maximus2012 13 hours ago
Right now its just a regular html form with the URL of the 3rd party form processor in the "action" field of the form. But I need a way to also redirect the user to a page I determine, after they submit the form instead of them going to the 3rd party processor. – Damainman 13 hours ago
What about curl to post the data to the third party processor? – Pep Lainez 13 hours ago
1  
This sounds like you can just POST/GET the form data directly through an ajax call to the third party processor. I don't know what this third party processor is, but it should be able to respond to your AJAX call. – Serguei Fedorov 13 hours ago

2 Answers

Using javascript and Ajax it can be done like this (with jQuery):

$("#idOfTheForm").submit(function(e) {
    e.preventDefault();
    $.ajax({
        method : "post",
        url : this.action,
        data : $(this).serialize(),
        success : function() {
            window.location = "yourUrlOfThanks.html";
        },
        error : function() {
            alert("Something went bad");
        }
    });
});

So basically it is: sent a post request to the action url of this form, and once it throws an 200 code (found and everything went ok) then redirect to my page. If soemthing went wrong, then the server will throw an 40* status code and the script will go into error function.

share|improve this answer

You can use Guzzle to proxy the user request.

    $client = new Guzzle\Http\Client();

    $request = $client->post('/3rd.party.php')
        ->addPostField('user_field_1', $_POST['user_field_1'])
        ->addPostField('user_field_2', $_POST['user_field_2']);

    $response = $request->send();

    if ($response->isSuccessful()) {
        //show message
    }

The downside is that you can't be 100% sure that the form submission was indeed successful. In order to achieve that you could scrap the $request->getBody() and check if a known success message is present.

share|improve this answer
Oh, and make sure you sanitize the data you get from $_POST! – xmarcos 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.