Documentation

gform_after_submission

  1. Description
  2. Usage
  3. Parameters
  4. Examples
    1. Example #1
    2. Example #2
  5. Placement
  6. Source Code

Description

This PHP action hook is executed at the end of the submission process (after form validation, notification, and entry creation). Use this hook to perform actions after the entry has been created (i.e. feed data to third party applications).
The Entry Object is available to this hook and contains all submitted values.

Usage

Applies to all forms

<?php
add_action( 'gform_after_submission', 'after_submission', 10, 2 );

Applies to a specific form. In this case, form Id 5

<?php
add_action( 'gform_after_submission_5', 'after_submission', 10, 2 );

Parameters

Examples

Example #1

This example uses the gform_after_submission hook to change the post content, adding values from submitted fields, including an image field.

add_action( 'gform_after_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:' . rgar( $entry, '7' ) . "<br/> <img src='" . rgar( $entry, '8' ) . "'> <br/> <br/> " . rgar( $entry, '13' ) . " <br/> <img src='" . rgar( $entry, '5' ) . "'>";

    //updating post
    wp_update_post( $post );
}

Example #2

This example demonstrates a simple approach to posting submitted entry data to a third party application:

add_action( 'gform_after_submission', 'post_to_third_party', 10, 2 );
function post_to_third_party( $entry, $form ) {
    
    $post_url = 'http://thirdparty.com';
    $body = array(
        'first_name' => rgar( $entry, '1.3' ), 
        'last_name' => rgar ( $entry, '1.6' ), 
        'message' => rgar( $entry, '3' ),
        );
    
    $request = new WP_Http();
    $response = $request->post( $post_url, array( 'body' => $body ) );
    
}

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This action hook is located in form_display.php