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.

Trying to get a form-specific hook to fire

  1. I'm trying to grab the value of a single form field, on a single form, and put it into a remote POST call.

    [php]
    add_action("gform_post_submission_4", "subscribe_textmarks", 10, 2);
    function subscribe_textmarks($entry, $form){
    
    //first, let's grab the phone number from the form, it's field 1
    $phone = get_post($entry["1"]);
    
    //now let's remotely subscribe to textmarks by calling their API via POST
    $response = wp_remote_post('http://help.api2.textmarks.com//Anybody/invite_to_group/', array(
    	'method' => 'POST',
    	'headers' => array(),
    	'body' => array( 'api_key' => 'chrislema_com__72225807', 'tm' => 'WORDPRESS', 'user' => $phone )
        )
    );
    }

    You can see by the initial _4 appended to the hook, I was trying to get this to only fire on a specific form.

    When I put in the value, the form submits, I see the thank you text, but nothing seems to get out to the remote server.

    Am I calling this wrong?

    Posted 11 years ago on Thursday August 30, 2012 | Permalink
  2. 1. gform_post_submission is deprecated. Please use gform_after_submission instead. Documentation

    2. Can you check the value of $response to see what it contains?

    3. Line 5 looks wrong. The WordPress function get_post is designed to return one post based on the integer value of the post ID. If you're trying to retrieve the phone number from a form entry, you probably want it to look like this (assuming the phone number is field 1 in your form):

    [php]
    $phone = $entry[1];
    Posted 11 years ago on Thursday August 30, 2012 | Permalink
  3. You rock. I had both issues - the deprecated code, and the incorrect reference for the entry variable. Now it works. Thanks!

    Posted 11 years ago on Thursday August 30, 2012 | Permalink
  4. Thanks for the update. Glad you got that working.

    Posted 11 years ago on Friday August 31, 2012 | Permalink

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