gform_post_enqueue_scripts

gform_post_enqueue_scripts

DescriptionUsageParametersExamplesBasic UsagePlacementSinceSource Code

Description
The gform_post_enqueue_scripts action hook is executed at the end of the process of enqueuing scripts and styles for each form embedded in the current page by shortcode or block.
Usage
1add_action( 'gform_post_enqueue_scripts', 'your_function_name', 10, 3 );

Parameters

$found_forms array
An array of found forms using the form ID as the key to the ajax status.

$found_blocks array
A filtered version of the array returned by parse_blocks containing only Gravity Forms blocks.

$post WP_Post
The page or post which was processed.

Examples
Basic Usage
12345add_action( 'gform_post_enqueue_scripts', function ( $found_forms, $found_blocks, $post ) {    foreach ( $found_forms as $form_id => $ajax_status ) {        // Do something for each form.    }}, 10, 3 );
Placement
This action hook should be used in the functions.php file of your active theme or a custom functions plugin.
Since
This hook was added in version 2.4.18.
Source Code
This hook is located in GFFormDisplay::enqueue_scripts() in form_display.php.

gform_post_data

gform_post_data

DescriptionUsageParametersExamples1. Change the post_type2. Change the post_status3. Set the post date4. Decode shortcodes in the post contentPlacementSource Code

Description
This filter is executed right before the post is created, allowing post data to be manipulated before the post is created.
Note: This filter only applies to forms that have Post Fields.
Usage
1add_filter( 'gform_post_data', 'your_function_name', 10, 3 );

Parameters

$post_data array
The array containing the post data to be filtered. This array is in the format used by the WP function wp_insert_post($post_data)

$form Form Object
The form currently being processed.

$entry Entry Object
The entry currently being processed.

Examples
1. Change the post_type
This example changes the default post type from post to page.
12345678910add_filter( 'gform_post_data', 'change_post_type', 10, 3 );function change_post_type( $post_data, $form, $entry ) {    //only change post type on form id 5    if ( $form['id'] != 5 ) {       return $post_data;    }     $post_data['post_type'] = 'page';    return $post_data;}
2. Change the post_status
This example sets the post status to private.
12345678910add_filter( 'gform_post_data', 'change_post_status', 10, 3 );function change_post_status($post_data, $form, $entry){    //only change post status on form id 5    if ( $form['id'] != 5 ) {       return $post_data;    }     $post_data['post_status'] = 'private';    return $post_data;}
3. Set the post date
This example sets the post date using date and time fields on the form.
12345678910111213141516171819202122232425262728add_filter( 'gform_post_data', 'set_post_date', 10, 3 );function set_post_date( $post_data, $form, $entry ) {  //only do this when the form id is 23  if ( $form['id'] != 23 ) {    return $post_data;  }   //set post date to field on form if date provided; get from entry data  //using a date field in mm/dd/yyyy format and a time field in 24 hour format  $date_value = rgar( $entry, '6' ); //pull the date value from the form data posted, field 6 on my form  $time = rgar( $entry, '7' ); //pull the time value from the form data posted, field 7 on my form  //only change post date/time when a date has been chosen  if ( ! empty( $date_value ) ) {    if ( empty( $time ) ) {      //set default time      $time_value = '00:00:00';    } else {      $time = explode( ':', $time ); //assumes you are using a time field in 24 hour format      empty( $time[0] ) ? $time_hours = '00' : $time_hours = $time[0]; //pull hours out of array      empty( $time[1] ) ? $time_minutes = '00' : $time_minutes = $time[1]; //pull minutes out of array      $time_value = $time_hours . ':' . $time_minutes . ':00'; //add on seconds    }    //convert post date to the appropriate format so it will be inserted into the database    $post_date = date( 'Y-m-d H:i:s', strtotime( $date_value . ' ' . $time_value ) );    $post_data['post_date'] = $post_date; //set the post_date  }  return $post_data; //return the changed data to use when the post is created}
4. Decode shortcodes in the post content
This example shows how you can decode the opening and closing brackets used by shortcodes in the post body field value.
12345678add_filter( 'gform_post_data', function ( $post_data ) {    $find    = array( '[', ']' );    $replace = array( '[', ']' );     $post_data['post_content'] = str_replace( $find, $replace, $post_data['post_content'] );     return $post_data;} );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFFormsModel::create_post() in forms_model.php.

gform_post_conditional_logic_field_action

gform_post_conditional_logic_field_action

DescriptionUsageParametersExamples1. Reset Coupon field2. Show/Hide the Save & Continue LinkPlacementSource Code

Description
This JavaScript hook can be used to perform custom actions when a field is displayed or hidden by conditional logic on the frontend.
Usage

Parameters

formId integer
The ID of the current form.

action string
The current conditional logic action. Possible values: show or hide.

targetId string
The ID selector for the field container (li) in the format #field_{formId}_{fieldId} e.g. #field_10_2

defaultValues string|array
The field default values.

isInit boolean
True when the form is initially displayed, otherwise false.

Examples
1. Reset Coupon field
The following example shows how you can reset the coupon field when hidden by conditional logic.
gform.addAction('gform_post_conditional_logic_field_action', function (formId, action, targetId, defaultValues, isInit) {
if (!isInit && action == 'hide') {
var target = jQuery(targetId),
coupon_items = target.find('tr.gf_coupon_item');

if (coupon_items.length) {
coupon_items.remove();
target.find('input[type=hidden]').val('').change();
}
}
});

2. Show/Hide the Save & Continue Link
This example shows how conditional logic can be used to show and hide the save and continue link at the same time as another field, in this case field 2 of form id 616.
gform.addAction('gform_post_conditional_logic_field_action', function (formId, action, targetId, defaultValues, isInit) {
if (targetId == '#field_616_2') {
if (action == 'show') {
jQuery('#gform_save_616_footer_link').show();
} else {
jQuery('#gform_save_616_footer_link').hide();
}
}
});

Placement
Your code snippet can be placed in a HTML field on your form or in a theme custom JavaScript file.
Source Code
This hook is located in js/conditional_logic.js

gform_post_category_choices

gform_post_category_choices

DescriptionUsageParametersExamples1. Sort the choicesPlacementSource Code

Description
The 「gform_post_category_choices」 filter in Gravity Forms can be used to alter the post category field choices when the form markup is being prepared.
Usage
The following would apply your function to all forms.
add_filter( 'gform_post_category_choices', 'your_function_name', 10, 3 );

To target a specific form append the form id to the hook name. (format: gform_post_category_choices_FORMID)
add_filter( 'gform_post_category_choices_5', 'your_function_name', 10, 3 );

To target a specific field on a specific form append the form id and the field id to the hook name. (format: gform_post_category_choices_FORMID_FIELDID)
add_filter( 'gform_post_category_choices_5_10', 'your_function_name', 10, 3 );

Parameters

$choices array
An multidimensional array containing the choices and their properties.

array(
array(
'text' => 'cat name 1',
'value' => 'cat id 1',
),
array(
'text' => 'cat name 2',
'value' => 'cat id 2',
),
)

$field Field Object
The current post category field.

$form_id int
The ID of the current form.

Examples
1. Sort the choices
This example demonstrates how to sort the choices numerically.
add_filter( 'gform_post_category_choices_5_10', function ( $choices, $field, $form_id ) {
// usort calls a custom sort function you create.
usort( $choices, 'sort_numerically' );

return $choices;
}, 10, 3 );
function sort_numerically( $a, $b ) {
return floatval( $a['text'] ) > floatval( $b['text'] );
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::add_categories_as_choices() in common.php.

gform_post_category_args

gform_post_category_args

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to change the $args passed to the WordPress get_terms() function and filter the list of categories displayed when a post category field is configured with the 「display all categories」 setting selected.
Usage
The following would apply your function to all forms.
1add_filter( 'gform_post_category_args', 'your_function_name', 10, 2 );
To target a specific field append the field id to the hook name. (format: gform_post_category_args_FIELDID)
1add_filter( 'gform_post_category_args_5', 'your_function_name', 10, 2 );

Parameters

$args array
The args being filtered. See the WP_Term_Query::__construct() codex article for the possible arguments.
1$args = array( 'hide_empty' => false, 'orderby' => 'name', 'taxonomy' => 'category' );

$field Field Object
The current post category field.

Examples
The following example demostrates how to exclude a category (category with ID=12) from the list of categories:
12345add_filter( 'gform_post_category_args', 'change_categories', 10, 2 );function change_categories( $args, $field ) {    $args['exclude'] = '12';    return $args;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFCommon::add_categories_as_choices() in common.php.

gform_post_calculation_events

gform_post_calculation_events

DescriptionUsageParametersExamplePlacementSource Code

Description
This filter can be used to register custom methods for triggering calculations.
Usage
123gform.addAction( 'gform_post_calculation_events', function ( mergeTagArr, formulaField, formId, calcObj ) {    // do stuff} );

Parameters

mergeTagArr array
The merge tag being processed.
mergeTagArr[0] contains the full merge tag e.g. {Field label:ID:modifier}
mergeTagArr[1] contains the field or input ID e.g. 2
mergeTagArr[3] contains the modifier(s) including the colon e.g. :value
mergeTagArr[4] contains the modifier(s) without the colon e.g. value

formulaField Javascript Object
The current calculation field object. e.g.
1{"field_id":3,"formula":"{:1}+{:2}","rounding":""}

formId integer
The ID of the form in use.

calcObj Javascript Object
The calculation object.

Example
This example shows how you can trigger calculations by adding or removing List field rows or modifying the value of a List field input.
12345678910111213141516171819gform.addAction( 'gform_post_calculation_events', function ( mergeTagArr, formulaField, formId, calcObj ) {    var fieldId = parseInt( mergeTagArr[1] ),        fieldSelector = '#field_' + formId + '_' + fieldId;     if ( jQuery( fieldSelector + ' table.gfield_list' ).length == 1 ) {        jQuery( fieldSelector )            .on( 'click', '.add_list_item', function () {                jQuery( fieldSelector + ' .delete_list_item' ).removeProp( 'onclick' );                calcObj.bindCalcEvent( fieldId, formulaField, formId, 0 );            } )            .on( 'click', '.delete_list_item', function () {                gformDeleteListItem( this, 0 );                calcObj.bindCalcEvent( fieldId, formulaField, formId, 0 );            } )            .on( 'change', ':input', function () {                calcObj.bindCalcEvent( fieldId, formulaField, formId, 0 );            } );    }} );
Placement
Your code snippet can be placed in a HTML field on your form or in a theme custom JavaScript file.
Source Code
This filter is located in js/gravityforms.js

gform_post_add_subscription_payment

gform_post_add_subscription_payment

DescriptionUsageParametersExamples1. Basic usage2. Cancel a Stripe subscription after # paymentsSource Code

Description
Triggered after a payment is made to an existing subscription.
Usage
add_action( 'gform_post_add_subscription_payment', 'my_function', 10, 2 );

Parameters

$entry Entry Object
The entry object that was created.

$action array
The action that occurred within the subscription payment. Contains further information about the subscription.
$action = array(
'type' => '',
'amount' => '',
'transaction_type' => '',
'transaction_id' => '',
'subscription_id' => '',
'entry_id' => '',
'payment_status' => '',
'note' => '',
);

Examples
1. Basic usage
function my_function() {
//Do something here
}
add_action( 'gform_post_add_subscription_payment', 'my_function', 10, 2 );

2. Cancel a Stripe subscription after # payments
See the Cancel a Stripe Subscription After a Specified Number of Payments article for an example showing how this hook can be used to cancel a Stripe subscription after a set number of payments have occurred.
Source Code
do_action( 'gform_post_add_subscription_payment', $entry, $action );
This action hook is located in GFPaymentAddOn::add_subscription_payment() in includes/addon/class-gf-payment-addon.php.

gform_post_add_entry

gform_post_add_entry

DescriptionUsageParametersExampleSource Code

Description
This hook fires after an entry has been added via GFAPI::add_entry().
Usage
add_action( 'gform_post_add_entry', 'your_function_name', 10, 2 );

Parameters

$entry Entry Object
The entry after being added.

$form Form Object
The form object.

Example
add_action( 'gform_post_add_entry', 'log_post_add_entry', 10, 2 );
function log_post_add_entry( $entry, $form ) {
GFCommon::log_debug( 'gform_post_add_entry: entry => ' . print_r( $entry, 1 ) );
}

Source Code
This action is located in GFAPI::add_entry() in includes/api.php.

gform_polls_results_ajax_response

gform_polls_results_ajax_response

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Allows the Ajax response to be overridden.
Usage
The following would apply to all forms:
add_filter( 'gform_polls_results_ajax_response', 'your_function_name', 10, 2 );

To target a specific form, append the form id to the hook name. (format: gform_polls_results_ajax_response_FORMID)
add_filter( 'gform_polls_results_ajax_response_1', 'your_function_name', 10, 2 );

Parameters

$response array
An associative array containing the properties to be returned in the Ajax response.
The properties available in the array are as follows:

canVote bool
Indicates if the user is allowed to vote.

resultsUI string
The results HTML, confirmation, or an empty string.

$form Form Object
The current form.

Examples
add_filter( 'gform_polls_results_ajax_response', 'change_result', 10, 2 );
function change_result( $response, $form ){
//change the color of the text of the first question
$response['resultsUI'] = str_replace('

', '

', $response['resultsUI']);
return $response;
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in the Gravity Forms Polls Add-On version 3.2.2.
Source Code
This filter is located in GFPolls::gpoll_ajax() in gravityformspolls/class-gf-polls.php.

gform_polls_percentage_precision

gform_polls_percentage_precision

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Allows the percentages on the front-end Polls results to be rounded to a custom number of decimal digits. The percentage is rounded to the nearest whole number by default.
Usage
1add_filter('gform_polls_percentage_precision', 'your_function_name', 10, 2);

Parameters

$precision int
The number of decimal digits to use.

$form_id int
The form id.

Examples
1234add_filter('gform_polls_percentage_precision', 'gform_polls_custom_precision', 10, 2);function gform_polls_custom_precision( $precision, $form_id ){    return 1;}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in the Gravity Forms Polls Add-On version 2.
Source Code
This filter is located in GFPolls::gpoll_get_data() in gravityformspolls/class-gf-polls.php