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.

Creating a WP post, sending query string and output AJAX confirmation

  1. Jamie
    Member

    Hi there,
    I've been searching Gravity Forms documentation and forums for the past week or so, but haven't found a solid solution yet. I've built a form that creates a Wordpress post and outputs an AJAX confirmation message. Now I need to pass the data in remaining fields to a third party mailing list service (which is unfortunately not MailChimp). I understand this is an incredibly complex hook, so would anyone have advice on the best way to craft this function, or possibly refer me to someone who could?

    Thanks for any help in advance.

    Posted 13 years ago on Wednesday February 16, 2011 | Permalink
  2. In order to integrate with a 3rd party mailing list service you would have to do so using API hooks when the form is submitted.

    You would want to use the gform_post_submission hook which has access to the Entry object. The Entry object all data from a submitted form.

    You can use the gform_post_submission 2 different ways.

    If you want to apply the code to ALL forms you would use it this way:

    <?php
    add_action("gform_post_submission", "post_submission", 10, 2);
    ?>

    If you want to apply the code to a SPECIFIC form you would use it this way, this example would target form id 5:

    <?php
    add_action("gform_post_submission_5", "post_submission", 10, 2);
    ?>

    Here is an example of the gform_post_submission in action, this example uses the gform_post_submission hook to change the post content, adding values from submitted fields, including an image field. It doesn't do what you want it to do, it's purely an example of the gform_post_submission usage:

    <?php
    add_action("gform_post_submission", "set_post_content", 10, 2);
    function set_post_content($entry, $form){
    
    //getting post
    $post = get_post($entry["post_id"]);
    
    //changing post content
    $post->post_content = "Blender Version:" . $entry[7] . "<br/> <img src='" . $entry[8] . "'> <br/> <br/> " . $entry[13] . " <br/> <img src='" . $entry[5] . "'>";
    
    //updating post
    wp_update_post($post);
    }
    ?>

    The gform_post_submission hook has access to the Entry object. Here are examples:

    $entry["date_created"];   //returns the entry date
    $entry["1"];              //returns the value associated with field 1
    $entry["2.4"];            //returns the value associated with the street input for the address field 2

    So you would use the field id OR keywords for default data associated with the entry. These keywords are:

    - id
    - date_created
    - is_starred
    - is_read
    - ip
    - source_url
    - post_id
    - FIELD_ID

    If this is all greek to you... then hiring a WordPress consultant to do the implementation may not be a bad idea. I would recommend:

    Ounce of Talent
    http://www.ounceoftalent.com

    WebDevStudios
    http://www.webdevstudios.com

    Posted 13 years ago on Wednesday February 16, 2011 | Permalink