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 form data to external handler

  1. jochan
    Member

    The only info I could find on the forum is from the following post:
    http://forum.gravityhelp.com/topic/cant-find-any-instructions-to-post-form-data-to-external-url

    My situation is similar, but I would appreciate it if you could point me to the right direction.

    So I'm using gravity form for client enquiries, currently the potential client will input all the details and the details will get sent to our mailbox which is pretty straigtforward. We then manually input the client info onto our CRM.

    However, we are changing the way we work, we start using a new CRM system, and the enquiry data can go direct to the CRM system via POST where we need to specify an action for the form. I see what you've done in the above forum topic, which is very similar to what i want, as I need to have input id and name specific to what the CRM required for this automation to work.

    So here are some problems specific to my situation:

    • the CRM only process leads submitted from approved URLs, so I'll need to let them know the url of the page hosting the form - however, if I submit the form using the wordpress action "gform_post_submission", how is it possible to specify the URL that the form is hosting from?
    • Also I'm relatively new to wordpress hooks and actions, this might be a dumb question, cos I already have a function added to "gform_post_submission", so it's ok to and another one right? like there's not limit to the number of actions right?
    • Thank you very much for your help!

    Posted 13 years ago on Thursday May 20, 2010 | Permalink
  2. You can have multiple actions places on the gform_post_submission hook.

    Currently you can't automatically post all the data to a URL. It is possible to redirect to a URL and then pass the data to it that way. This would be a GET method. Does your CRM support GET or only POST?

    Posted 13 years ago on Thursday May 20, 2010 | Permalink
  3. jochan
    Member

    I would imagine it's only POST...
    but when I was looking at this forum topic, http://forum.gravityhelp.com/topic/cant-find-any-instructions-to-post-form-data-to-external-url - the code uses POST as well (see below)

    add_action("gform_post_submission", "post_to_crm", 10, 2);
    
    function post_to_crm($entry, $form){
        if($form["id"] != 3) //NOTE: replace 3 with your form id
            return;
        ?>
            <form method="post" action="http://crm.zoho.com/crm/WebToLeadForm" name="form_to_crm" id="form_to_crm">
                <input type="hidden" name="name" value="<?php echo $entry["1"] ?>" />
                <input type="hidden" name="email" value="<?php echo $entry["2"] ?>" />
                <input type="hidden" name="phone" value="<?php echo $entry["3"] ?>" />
                NOTE: $entry["1"] will return field with ID=1. You can view the field ID by inspecting that input's markup
                .... add your other fields here
    
            </form>
            <script type="text/javascript">
                document.getElementById("form_to_crm").submit();
            </script>
        <?php
    }

    can I not achieve my goal via this method?
    but a problem remains, I don't know how to specify a from URL when the from is submitted using inside php codes

    Thanks for your help

    Posted 13 years ago on Monday May 24, 2010 | Permalink
  4. jochan,
    The sample above should work with the POST you are looking for.
    As far as the "from" URL, it will be the same URL as the page you see your form in. The reason for that is that Gravity Forms posts to the same page and the hook runs within that context. Makes sense?

    Attaching multiple functions to a hook is possible, but you won't be able to have two of them with the code of the sample above. The reason is that the sample above will render the form in the page and then immediately post it to URL specified. If you add two of them, they will both try to post at the same time and only one of them will actually post. The other will just be ignored.

    Let us know how it goes.

    Posted 13 years ago on Thursday May 27, 2010 | Permalink
  5. hey guys... i am an not a php expert but can fiddle with other peoples codes... let me know if this should be a new topic... however i want to post a lead to my crm (heap crm) through the crm API...

    the php code would look something like this...

    http://www.pastie.org/1703737

    could you give me an example of how this code might be included in an hook to be inserted in functions.php?

    Posted 13 years ago on Wednesday March 23, 2011 | Permalink
  6. Hi Andy, this should be a good start: http://www.pastie.org/1706001

    Posted 13 years ago on Wednesday March 23, 2011 | Permalink
  7. thanks...

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  8. David... i made a plugin to wordpress and uploaded it...

    http://pastie.org/1729536

    I also tried the same code in function.php. Neither seemed to work. What would be the best way to confirm that the data from the form is coming through? I posted on the heap forums to see if ben the owner/ developer can figure out what errors i made on the heap side...

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  9. *** PROPOSED SOLUTION ***

    Andy - Your code indicates you are posting to a secure (https) url. I just resolved a similar issue with the GF PayPal Plugin posting a secure site from my development test server.

    I posted a solution to my issue in the following link:
    - http://www.gravityhelp.com/forums/topic/solution-to-an-issue-i-had-with-http-posts-to-paypal

    While I explain a solution that worked for me, your situation is much different in that you are explicitly using the CURL API to post your data. My situation involved using the WP_Http class.

    A quick way to test if your issue is related to the CA Cert, add the following CURL Options to the code you shared on: http://pastie.org/1729536

    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

    **** WARNING: DO NOT USE THE ABOVE SETTINGS FOR GENERAL Production Purposes. This basically disables the SSL verification altogether. ****

    If this test allows you to successfully send your HTTP Post, then complete the following steps to resolve this issue:

    1. Remove the test CURL Options from your code.

    1. Download a recent CA cert to your webserver from: http://curl.haxx.se/docs/caextract.html. The direct download link is: http://curl.haxx.se/ca/cacert.pem.

    2. If running WordPress on Windows, you can change the extension from .pen to .crt.

    3. Add the following lines to your code:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_CAINFO, 'E:\enter\your\path\to\cacert.crt');

    Let me know if this got you past your current issues.

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  10. Andy,

    Another way to test your code is to use the developer WordPress Plugins listed below:

    - http://wordpress.org/extend/plugins/debug-bar/
    - http://wordpress.org/extend/plugins/debug-bar-console/

    I modified your original script with some logging hooks to demonstrate how to use this plugin when debugging your code.

    - http://pastie.org/1730484

    Follow my detailed notes in the header of this script and hopefully they'll make sense.

    Just remember to deactivate these plugins when you are not testing your code.

    Best Regards,

    David Carroll

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  11. holy shit... i really am a noob... that debug script you ran just posted 10 bob the waterboys to the crm... i guess changing the password doesn't matter the... hook must not require a good password... :) funny... thanks... well if your debug script works... i am not to far off.

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  12. wow... thanks so much... amazing what you can figure out when you log stuff and see what is going out... thanks again!!!!

    no what the problem was??? it was simply that i wasn't referencing proper field id's... is there a better way to get the field id other than to look it up in the source code of the form?

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  13. thanks softrealty...

    i got it working thanks to your debug... for anyone else who wants to get gravity forms working with heap here is the plugin code... just upload in a php file in a subdirectry of plugins

    http://www.pastie.org/1731116

    you know what the problem was??? i was referencing the wrong gravity form field id... o.k. one other question... is there a way to reference field name instead of field id number in this? that way i can make this a universal script for various forms that i create and they all get sent to heap crm even if they have varying field id's.

    Posted 13 years ago on Tuesday March 29, 2011 | Permalink
  14. *** NOTE: FOR DEVELOPERS ONLY ***
    Andy,

    It took me a while to figure out how to solve the problem you asked about. Basically, you wanted to know if there was a way to retrieve values via code from the $entry array without having prior knowledge of the numeric input id's used as array keys.

    For Example:
    The value for the Phone Number field from a posted GForm might be retrieved with the following line:

    $phone = $entry[19];

    However, you would need to have prior knowledge that 19 is the id for accessing the phone number field for this GForm. You would prefer to access the value submitted for Phone Number with the following line:

    $phone = $entry['phone'];

    Perhaps the GravityForms guys can give some insight on this. Since I'm reviewing the GF plugin code to better understand the architecture for another plugin I want to create, I decided to take a stab at this.

    Please review the new helper functions I created and the rest of this post to see how I was able to accomplish what you were looking for.

    View New Code Page: http://www.pastie.org/1736319

    **** DISCLAIMER ****
    You will need to review this entire post to understand how to configure your GForm settings for this code to work. This code is provided AS-IS, works on my server and specific environment settings, uses id's based on my GravityForms setup, and may change if an update is made to the GF Plugin.
    *************************

    That said, I did add a lot of code comments and this very detailed post to help you modify the helper for your own use. While all the code is on one file, I recommend moving some of these methods to common locations as appropriate. You could also consider moving some of these fragments into their own namespaces.

    ** Improvement: LogConsole **
    One major improvement in this updated code is you don't have to comment out all the LogConsole() lines. There are security and context checks in place now that will only run those logs if being called from debug-bar-console plugin as the site super admin.

    ** Setup Your GForm to Work with Test **
    To get started, you'll need to do a few things on your GF configurations first:

    1. GF User Registration Plugin is required. Make sure this is installed.

    2. Go to Form Editor for the form you want to test.
    - Make sure you have fields for the following:
    - Username
    - Site Name
    - First Name
    - Last Name
    - Email Address
    - Phone Number

    Apply update to the GForm.

    3. Locate GForm form_id
    Take note of the form_id for this GForm. You can get this from the Form List Page. It's also in the querystring when viewing in the Form Editor as form_id. If your form_id is not 1, then you'll need to update the test method:
    - BuildMockEntryArray( $form_id = 1 , [... other params .. ]) { }
    Replace 1 with the ID that matches your form.

    4. Go to GF User Registration Settings Page:
    - Edit the User Registration Settings you want to test this GForm with. Create a new one if you don't already have one created.
    - Select the GForm you want to use.
    - Map the following Standard Fields:
    - Username
    - First Name
    - Last Name
    - Email Address
    - Create 2 new Custom User Meta Settings:
    - Site Name
    - Phone
    NOTE: Use the names for this test exactly as you see them. This is case sensitive.
    - Map these values to your GForm Fields.
    - Save your changes.

    ** Debug-Bar-Console Test will Only Work From Page Hosting GForm **
    1. Testing this with debug-bar-console must be done on a page that has a reference to this GForm.

    2. You must also be logged in as the site super admin. Add the GForm to a new page and go to the page in view mode.

    3. From the page hosting the GForm, open debug-bar-console plugin
    and Run the following line:

    GFHeapTestHarness();

    ** Reviewing the Log Output: **
    1. To verify numeric keys are matched to friendly named keys, locate the first Array in the output window:

    GetGFormEntryKeys() - $entry_keys::Array
    (
        [username] => 4
        [firstname] => 1.3
        [lastname] => 1.6
        [email] => 2
        [Site Name] => 3
        [Phone] => 19
    )

    This log message shows the code was able to dynamically match the numeric keys with the friendly name.

    2. To verify your code retrieved posted content without prior knowledge of the field id's, locate the following logs near the bottom of the output window:

    prepare_for_heap() - $leaddata::Array
    (
        [create] => lead
        [name] => Bobby Boucher
        [phone] => 555-555-5555
        [email] => bobby@ilovedafootball.com
    )
    Test key: Site Name::waterboy_movie
    Test key: Phone::555-555-5555

    This log message shows the values were able to be retrieved from $entry without knowing the numeric keys ahead of time. All you need to know are the User Meta Setting names.

    If there are any errors or if data isn't being loaded, review the default array values in BuildMockEntryArray() and verify $form_id matches the current GForm form_id.

    ** Where Can We Go From Here **
    I plan on converting this into a mapping plugin that will also attempt to map input id's to the [Admin Label] Setting in the Advanced Tab of each field on a form. This should be fairly easy and only require changing the function GetGFormEntryKeys() so it loads the GForm settings for the specified form_id.

    Another option would be to create a dedicated mapping page for developers to use specifically for this purpose. I could then create a class that extend the $entry array and provides the named keys for server side data mapping.

    ** Thoughts from GF Team **
    Whew... that was a lot to present. Perhaps the GravityForms team can confirm if there is a more native way to do this via the current code base. At the very least, I've learned a lot about how GForm is setup and works.

    Thanks,

    David Carroll

    Posted 13 years ago on Wednesday March 30, 2011 | Permalink
  15. @David i'll have Alex, our lead developer, take a look and give his input. It may be a little bit before he does so, maybe not until later this week when he can digest this post, etc.

    We actually would like to create an Add-On that allows you to easily post data to an external handler as part of the form submission process and do exactly what you outlined as far as mapping fields. You'd select fields and map them to what name it should post as to the external handler. So it is something we'd like to create an official Add-On, or work with a 3rd party developer to create it.

    Posted 13 years ago on Wednesday March 30, 2011 | Permalink
  16. @Carl - I just edited my post to do a better job introducing what is being addressed for future readers.

    That said, your suggestion for an Add-on to map existing fields to external APIs is exactly what I was thinking.

    My initial thoughts on this would be for the API Add-on to support the following modules:
    - Template Library Module (PayPal, eBay, Zillow, Trulia, various CRMs, or Custom)
    - Protocol Modules (HTTP, SMS, SOAP, Email, Database, etc)
    - Saved API Configurations (Similar to Forms List where each item specifies the Template, Mapped Fields, and Protocol that are bound together for the current configuration.)

    Additionally, a history of all API Submissions and third-party postbacks could be viewed for each Published API Configuration.

    Obviously, this should start out small with only 1 or 2 supported modules. However, it could lay the ground work for future efforts to pull in a workflow plugin that would work with these API Submissions and Postbacks.

    In the meantime, the Module approach could give the community the opportunity to contribute various Templates. For example, real estate agents could start to post listings to sites like Trulia, Zillow, Craiglist. Online retailers could push products to Google Store, eBay, etc. You guys are already doing this specifically for Freshbooks and MailChimp. Pushing contacts to any number of CRMs that support Restful API's, such as Heap, SalesForce, HireriseHQ, would probably be popular with users and other companies.

    Anyway, I'm just thinking out loud and this may be more than you care to consider for the plugin. It's a cool concept non-the-less.

    Thanks,

    David Carroll

    Posted 13 years ago on Wednesday March 30, 2011 | Permalink