PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

POST request to external CRM

  1. tictok
    Member

    HI all - Hoping you can help.

    Wordpress, php etc is still fairly new to me to please be gentle!

    I have a simple gravity form (with a dev license) on a site to collect customer / user details.

    What I now need to do is that when the user submits the form, the details are sent as a POST request to a specific external URL so that user details are filled in within the clients CRM.

    I don't have any idea how to go about doing this? Could someone point me in the right direction please.

    If at all possible I don't want the user to visibly leave the website (i.e. don't want them to see or visit the CRM).

    I've had a search around the forum and not found exactly what I want, but imagine it has something to do with Query Strings?

    Many thanks!
    Stef

    Below is a little background :

    About a year ago I updated and transitioned a simple site to wordpress for a client (www.energymyway.co.uk) which I'd previously built the year before using ModX as its CMS.

    My client now employs someone to manage the site, fill in blog posts, and generally add pages and update things.

    They've recently has a custom CRM built to help manage customer details and have requested that I update the contct form so that when someone fills in their details the CRM is updates with that info. They have requested that the details are sent via a POST request to a specific URL.

    Posted 13 years ago on Wednesday February 2, 2011 | Permalink
  2. This thread might be helpful to you:

    http://forum.gravityhelp.com/topic/post-form-data-to-external-handler#post-5684

    Posted 13 years ago on Wednesday February 2, 2011 | Permalink
  3. tictok
    Member

    Fantastic - thanks!
    Not sure how I missed that post.
    Tweaking and placing that chuck of PHP in my functions.php file has got me 90% of the way there.

    add_action("gform_post_submission", "post_to_crm", 10, 2);
    
    function post_to_crm($entry, $form){
        if($form["id"] != 2) //NOTE: replace 2 with your form id
            return;
        ?>
    
    <form method="post" action="http://receive-form.co.uk/"
    name="form_to_crm" id="form_to_crm">>
    
    <input type="hidden" name="first_name" value="<?php echo $entry["1"] ?>" />
    <input type="hidden" name="last_name" value="<?php echo $entry["2"] ?>" />
    
            </form>
     <script type="text/javascript">
    document.getElementById("form_to_crm").submit();
    </script>
    <?php
    }

    However, what I know need to figure out is how to send (POST) the form values from website 'A', to the CRM (on website 'B') without the user visibly visiting or ending up on website 'B'.

    With the current method the user ends up on the confirmation message on the CRM website. I need it to appear as if they never leave the first website.

    How would I go about creating a php snippet to do this so the form values are sent to the CRM in the background or otherwise? Would it be something to do with altering the submit process?

    Hope you can help
    Many thanks
    Stef

    Posted 13 years ago on Thursday February 3, 2011 | Permalink
  4. Try the following

    add_action("gform_post_submission", "post_to_crm", 10, 2);
    
    function post_to_crm($entry, $form){
        if($form["id"] != 2) //NOTE: replace 2 with your form id
            return;
        ?>
    
    	//change this string to add your variables
    	$req = "email={$entry["1"]}&first_name={$entry["2"]}";
    
    	//change to your crm url
    	$url = "http://your_crm_url.com";
    
    	$request = new WP_Http();
    	$response = $request->post($url, array("body" => $req));
    <?php
    }
    Posted 13 years ago on Monday February 7, 2011 | Permalink
  5. mneisser
    Member

    I had the same issue as tictok. I've setup and tested using the javascript post and it posts correctly to my crm. The crm lets me set a redirect back to my site, but the issue is the amount of time to process. I would prefer to use Alex's method behind the scenes. I tried Alex's code and after form submission it doens't post to the external site, but I just see the code above my form. I'm using the following code. Do I just have a typo?

    add_action("gform_post_submission", "post_to_crm", 10, 2);
    
    function post_to_crm($entry, $form){
        if($form["id"] != 4) //NOTE: replace 3 with your form id
            return;
        ?>
                function post_to_crm($entry, $form){
        if($form["id"] != 4) //NOTE: replace 2 with your form id
            return;
        ?>
    
    	//change this string to add your variables
    	$req = "w2lid=xxxxxxxxx&lead[first_name]={$entry["1.3"]}&lead[last_name]={$entry["1.6"]}";
    
    	//change to your crm url
    	$url = "https://www.pipelinedeals.com/web_lead";
    
    	$request = new WP_Http();
    	$response = $request->post($url, array("body" => $req));
    <?php
    }

    screenshot: http://ScrnSht.com/hnfenw

    Posted 13 years ago on Tuesday February 8, 2011 | Permalink
  6. Sounds like you don't have an opening <?php at the beginning, so it's being processed at HTML/text by your theme when functions.php is included.

    Try adding to the snippet above, as the first line:

    <?php

    You probably have a closing ?> just above where you added this snippet to your functions.php.

    Posted 13 years ago on Tuesday February 8, 2011 | Permalink
  7. mneisser
    Member

    got it thanks. it actually was the closing ?> within the function that existed from the prior code .

    function post_to_crm($entry, $form){
        if($form["id"] != 2) //NOTE: replace 2 with your form id
            return;
        ?>
    Posted 13 years ago on Tuesday February 8, 2011 | Permalink

This topic has been resolved and has been closed to new replies.