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.

gform after submission - works with multiple forms?

  1. loxllxol
    Member

    Is there a way to specify which "gform after submission hook" to perform based on which form is used?

    For example:

    Form A > Submits to URL A
    Form B > Submits to URL B

    The problem I am running into, is that gform after submission hook submits the same values no matter what form is used. This is a problem because different forms have different $entry numbers and values.

    ($entry 1 may be the first name on Form A, but may be an email address on Form B).

    Here is my gform after submission (which works perfectly BTW, when only using ONE FORM. The problem starts when I create multiple gravity forms).

    // Post to SAGE CRM
    add_action('gform_after_submission', 'post_to_third_party', 10, 2);
    function post_to_third_party($entry, $form) {
    
        $post_url = 'http://sage.cpssecurity.com/cpssage/eware.dll/SubmitLead?RuleID=';
        $body = array(
            'lead_personfirstname' => $entry['1.3'],
            'lead_personlastname' => $entry['1.6'],
            'lead_companyname' => $entry['2'],
    		'lead_description' => $entry['2'],
    		'lead_personemail' => $entry['3'],
    		'lead_personphonenumber' => $entry['4'],
    		'lead_servicetype' => $entry['10'],
    		'lead_cprojvalue' => $entry['11'],
    		'lead_details' => $entry['5'],
    		'lead_decisiontimeframe' => $entry['16'],
    		'lead_subid' => $entry['12'],
    		'lead_campaign' => $entry['13'],
    		'lead_source' => $entry['14'],
    		'lead_companystate' => $entry['15']
            );
    
        $request = new WP_Http();
        $response = $request->post($post_url, array('body' => $body));
    
    }
    Posted 11 years ago on Thursday August 30, 2012 | Permalink
  2. Take a look at the documentation. You can add a form ID to the hook, like this

    gform_after_submission_4

    where 4 is your form ID.

    Posted 11 years ago on Thursday August 30, 2012 | Permalink
  3. loxllxol
    Member

    You're the man!! Totally solves my problem...thanks!

    Posted 11 years ago on Thursday August 30, 2012 | Permalink
  4. You're welcome. Most filters and hooks in Gravity Forms work that way. When they do not, we have a work around for you to process the code only for specific forms.

    Posted 11 years ago on Thursday August 30, 2012 | Permalink
  5. loxllxol
    Member

    Chris, I updated functions.php with the following code:

    // Post Form 1 MAIN FORM to SAGE CRM
    add_action('gform_after_submission_1', 'post_to_third_party', 10, 2);
    function post_to_third_party($entry, $form) {
    
        $post_url = 'http://sage.cpssecurity.com/cpssage/eware.dll/SubmitLead?RuleID=';
        $body = array(
            'lead_personfirstname' => $entry['1.3'],
            'lead_personlastname' => $entry['1.6'],
            'lead_companyname' => $entry['2'],
    		'lead_description' => $entry['2'],
    		'lead_personemail' => $entry['3'],
    		'lead_personphonenumber' => $entry['4'],
    		'lead_servicetype' => $entry['10'],
    		'lead_cprojvalue' => $entry['11'],
    		'lead_details' => $entry['5'],
    		'lead_decisiontimeframe' => $entry['16'],
    		'lead_subid' => $entry['12'],
    		'lead_campaign' => $entry['13'],
    		'lead_source' => $entry['14'],
    		'lead_companystate' => $entry['15']
            );
    
        $request = new WP_Http();
        $response = $request->post($post_url, array('body' => $body));
    
    }
    // Post Form 1 INTERNAL SALES to SAGE CRM
    add_action('gform_after_submission_2', 'post_to_third_party', 10, 2);
    function post_to_third_party($entry, $form) {
    
        $post_url = 'http://sage.cpssecurity.com/cpssage/eware.dll/SubmitLead?RuleID=';
        $body = array(
            'lead_personfirstname' => $entry['1.3'],
            'lead_personlastname' => $entry['1.6'],
            'lead_companyname' => $entry['2'],
    		'lead_description' => $entry['2'],
    		'lead_personemail' => $entry['3'],
    		'lead_personphonenumber' => $entry['4'],
    		'lead_servicetype' => $entry['10'],
    		'lead_cprojvalue' => $entry['11'],
    		'lead_details' => $entry['5'],
    		'lead_decisiontimeframe' => $entry['16'],
    		'lead_subid' => $entry['18'],
    		'lead_campaign' => $entry['13'],
    		'lead_source' => $entry['14'],
    		'lead_companystate' => $entry['15']
            );
    
        $request = new WP_Http();
        $response = $request->post($post_url, array('body' => $body));
    
    }

    However, when I include the 2nd gform_after_submission_2, my wordpress loads a blank page. When I remove the 2nd gform_after_submission_2 code, the wordpress install loads fine.

    Any ideas?

    Posted 11 years ago on Thursday August 30, 2012 | Permalink
  6. David Peralty

    You can't name both of your functions the same. Try having post_to_third_party and post_to_internal or something.

    Posted 11 years ago on Thursday August 30, 2012 | Permalink
  7. loxllxol
    Member

    ^^^ YUP! That fixed it...thanks!!

    Posted 11 years ago on Thursday October 4, 2012 | Permalink
  8. David Peralty

    No problem. Glad it helped.

    Posted 11 years ago on Thursday October 4, 2012 | Permalink

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