Pass data to a 3rd party application that accepts POST data.

  • gmccanna
    Asked on January 9, 2017 at 3:10 PM

    I need to Post my form data to my ERP system through a specific URL. I followed these instructions (https://www.jotform.com/help/213-Send-Submission-Data-via-POST-Method-Using-PHP-and-the-Thank-You-Settings) to get the Post data via the Thank You page. From what I've read, I now need to write some PHP code to have this data Post to a URL.

    I found a very nice article in the User Guide, "How-To How to send Submissions to Your MySQL Database Using PHP", which contains some very nice sample code, but couldn't find any documentation, code, or a "How-To Guide" to simply Post the data to a specific URL.

    Do you have any sample PHP code to demonstrate how to Post form data to a URL?

  • Chriistian Jotform Support
    Replied on January 9, 2017 at 5:43 PM

    Hi there,

    Do you mean you want to send post data using PHP code to some URL? You might need to use CURL functionalities of PHP. Please see for an example below.

    ---------------------------------------------------------------

    $url = 'http://www.example.com';

    $myvars = 'myvar1=' . $myvar1 . '&myvar2=' . $myvar2;

     

    $ch = curl_init( $url );

    curl_setopt( $ch, CURLOPT_POST, 1);

    curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);

    curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);

    curl_setopt( $ch, CURLOPT_HEADER, 0);

    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);

     

    $response = curl_exec( $ch );

    ---------------------------------------------------------------

     

    You can try adding this to your existing PHP code which is currently catching the POST data from your form. If you are referring to a different concern, let us know.

    Regards.

  • gmccanna
    Replied on January 9, 2017 at 6:05 PM

    Thank you for the quick response! And no, I would actually prefer not to use any code to Post my form data to some URL, but from the research I've done on JotForm, using PHP seems to be the only solution to get the data to the URL. If there is another way to do it, I'd love to know!  But if this is the only method to achieve my goal, I can live with that, but just need a little more assistance.

    Please excuse my next question because I am not a developer and have limited coding skills, but how do I incorporate the Post Data I received from the Thank You page into the code you provided above? If you could provide a completed PHP CURL script using sample data it would be much appreciated!

    Thanks again for such great help!

  • Chriistian Jotform Support
    Replied on January 9, 2017 at 8:39 PM

    You will need to create a custom page where you can insert the php code and redirect the Thank You page there. For example, you have the PHP code in a page with the link http://www.mysite.com/redirect.php. As seen in this guide, you will then redirect the Thank You page into that link.

    Pass data to a 3rd party application that accepts POST data Screenshot 20

    If you want to send the data through a url, you can then use this php code to direct the third party application.

    <?php

     $referrer= $_POST['referrer'];

     header("location:http://www.mydomain.com/page2/?page1_s=".$referrer);

    ?>

    Another alternative I can suggest would be to use Webhooks for your requirement. Please see our guide here on How to Setup a Webhook with JotForm

    Regards.