0

How extract php response query string after posting data to external server using html post form?

page:delivery.php

<form name="form2" method="post" action="http://dev.site.com/pay/transactionresult" id="form1">
    <input type="hidden" value="<?php echo $amt;?>" name="amt" />
    <input type="hidden" name="merchant" value="abc">
    <input type="hidden" name="orderid" value="<?php echo $orderid;?>">
    <input type="hidden" name="referenceid" value="<?php echo  $referenceid;?>">
    <input type="submit" value="submit"/>
</form>

I think the outcome is xml as the developer guide shows

Response

<response>
    <response_code>
        success
    </response_code>
</response>

<response>
    <response_code>
        failure
    </response_code>
</response>

How to get the response ? Please show in code. can the response code be in the delivery.php?

fejese
  • 4,353
  • 4
  • 25
  • 35
  • Extract Response? Response from who, the person submitting the survey on the website, or response from the server upon successful receipt of info from the form and after that data is stored in a database somewhere? I'm assuming there are some user responses.. if not, I don't think you'd have a submit button (?) – zipzit Jul 16 '15 at 08:26
  • Let me ask my question in a different way. Do you understand this example? http://www.the-art-of-web.com/php/form-handler/ When you understand how the submit works, with a post type data, your final questions aren't clear at all. Are you asking how to grab post type data, validate it and then process it into a database? – zipzit Jul 16 '15 at 08:48
  • @zipzit This is to get response from remote server (resellerclub) after receiving payment from a payment gateway – Darren Newmark Jul 16 '15 at 09:04
  • Who controls `http://dev.site.com/pay/transactionresult`?.. you or a payment service? If that's a controller on your server, then you can make it do what ever you want (JSON, XML or whatever you choose) You will write the REST server. If thats a service (like paypal, or mastercard or square or mercury pay) then you will have to read their full documentation to see what data they will return to you. Note: Square has very well written API documentation guides. – zipzit Jul 16 '15 at 09:19

3 Answers3

1

IF you want to handle the response to a post to a remote server you have to perform the post on the server side, not by the client (browser).

So something like this would be the idea:

client --POST--> your server --response--> client
                  |      ^
                 POST    |
                  |   response
                  V      |
                remote server

So you show a page to the user where he can fill in the required data then post it to a form handler page on your server. That handler page can make the request to the remote server and parsing the response it can generate the appropriate answer to the client.

You can use CURL for example to make the remote request on the server side.

An example would be something like this: (CURL example based on an other SO answer)

<?php
if (empty($_POST['amt'])) {
  // show form
} else {
    $data = ...; // collect and filter data from form

    $ch = curl_init();

    curl_setopt($ch, CURLOPT_URL,"http://remote.example.com/transaction");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));

    // receive server response ...
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $server_output = curl_exec ($ch);

    curl_close ($ch);

    // further processing ....
    if ($server_output == "OK") {
        // parse $server_output
        $message = 'success';
    } else {
        $message = 'error';
    }

    // show $message to user
}
?>

This example by no means complete but hopefully gives you an idea.

Community
  • 1
  • 1
fejese
  • 4,353
  • 4
  • 25
  • 35
1

I'm getting the impression that you are just learning programming but you want use the services of http://www.resellerclub.com/domain-reseller/api to sell products to customers.

One choice is to have the customers submit a form that goes directly to the resellerclub, but their return isn't so friendly for that. An alternative is to have your users submit a form to YOUR SERVER, and then your server does the request to resellerclub.com. (via CURL) You will get a response from reseller club (strongly recommend http JSON option!) and you can do what ever you like with that data (generally provide a response back to the website user, thanking them for their submission )

To do that you'd have to change your form action= to action="darrens_server.com/payment_submission.php" and within that php file is where you would submit stuff to resellerclub, wait for a response, and echo results back to the website user.

I will say, if credit cards are involved this might not be the best way to go. Generally I steer clear of handling credit card transactions, I want a money company to do that for me (e.g. paypal) I don't need the liability that something goes wrong or that anybody in my company can even see a user's credit card number. The whole processing thing is really up to resellerclub.com in this case. You need to follow their rules.

Good luck with it.

zipzit
  • 2,776
  • 3
  • 24
  • 44
0

After you submit this form to the external server, the response will be sent to your browser, not to your server.

freytag
  • 4,374
  • 2
  • 25
  • 28