gform_ip_address

gform_ip_address

DescriptionUsageParametersExamples1. Use HTTP_X_FORWARDED_FOR2. Prevent the IP address being saved3. Use CloudFlare』s CF-Connecting-IP headerPlacementSinceSource Code

Description

Allows the IP address of the client to be modified. Use this filter if the server is behind a proxy.

Usage

add_filter( 'gform_ip_address', 'your_function_name' );

Parameters

$ip string
The IP being used.

Examples

1. Use HTTP_X_FORWARDED_FOR

Use this if you are behind a proxy. This example will use HTTP_X_FORWARDED_FOR, allowing the visitor IP to be displayed instead of the proxy IP. This is just an example valid for a common scenario, if it』s not working for you, contact with your host support for assistance.

add_filter( 'gform_ip_address', 'filter_gform_ip_address' );

function filter_gform_ip_address( $ip ) {
// Return the IP address set by the proxy.
// E.g. $_SERVER['HTTP_X_FORWARDED_FOR'] or $_SERVER['HTTP_CLIENT_IP']
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}

2. Prevent the IP address being saved

add_filter( 'gform_ip_address', '__return_empty_string' );

3. Use CloudFlare』s CF-Connecting-IP header

According to CloudFlare』s documentation, the client (visitor) IP address is passed using the CF-Connecting-IP header, use the snippet below to make Gravity Forms use this HTTP header.

add_filter( 'gform_ip_address', 'cloudflare_gform_ip_address' );

function cloudflare_gform_ip_address( $ip ) {
// Return the IP address provided by CloudFlare's CF-Connecting-IP header.
return $_SERVER['CF-Connecting-IP'];
}

Placement

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

Since

This filter was added in Gravity Forms v2.2.

Source Code

This filter is located in forms_model.php.

gform_insert_bulk_choices_choice

gform_insert_bulk_choices_choice

DescriptionUsageParametersExamples1. Add custom choice propertyPlacementSinceSource Code

Description
The gform_insert_bulk_choices_choice filter allows each choice to be overridden as it is added to the field using the Bulk Add Predefined Choices UI.
This filter is generally used in combination with gform_load_bulk_choices_choice, and is useful for parsing a unique text pattern (e.g., Label|Value|Other) and adding the additional data to the resulting Choice object.
Usage
The filter which would run for all forms and choice based fields that support the Bulk Add Predefined Choices UI would be used like so:
gform.addFilter( 'gform_insert_bulk_choices_choice', function( choiceObj, choice, field ) {
// do stuff

return choiceObj;
} );

Parameters

choiceObj Javascript Object
The object representing the choice currently being added to the field using the Bulk Add Predefined Choices UI e.g.
{
"text": "One",
"value": "1",
"isSelected": false,
"price": ""
}

This can also include custom choice properties.

choice string
The string representing the current choice as a text pattern usually in the format text|value e.g.
One|1

field Javascript Object | Field Object
The current field.

Examples
1. Add custom choice property
This example shows how you can add a custom property to the choice object if the choice string (e.g. One|1|#first) contains your custom property value (e.g. #first).
gform.addFilter( 'gform_insert_bulk_choices_choice', function( choiceObj, choice, field ) {
if ( choice.indexOf( '#' ) === -1 ) {
return choice;
}

var parts = choice.split( '|' );
choiceObj.value = parts[1];
choiceObj.mycustomprop = parts[2];

return choiceObj;
} );

Placement
This code should be placed in a JavaScript file included in the admin by your plugin.
Since
This filter was added in Gravity Forms v2.5.
Source Code
This filter is located in InsertBulkChoices() in form_editor.js.

gform_input_masks

gform_input_masks

DescriptionUsageParametersExamplesPlacementSource Code

Description
Use this filter to edit the list of built-in input masks that are displayed in the Text Field input mask setting. Useful when adding a new custom input mask that will be used repeatedly.
Usage
1add_filter( 'gform_input_masks', 'add_mask' );
Parameters

$masks array
Current list of masks to be filtered, in the following format:
123456789array(    'US Phone' => '(999) 999-9999',    'US Phone + Ext' => '(999) 999-9999? x99999',    'Date' => '99/99/9999',    'Tax ID' => '99-9999999',    'SSN' => '999-99-9999',    'Zip Code' => '99999',    'Full Zip Code' => '99999?-9999');

Examples
This example adds a new predefined mask for 「Product Key」.
12345add_filter( 'gform_input_masks', 'add_mask' );function add_mask( $masks ) {    $masks['Product Key'] = 'a*-999-a999';    return $masks;}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFFormsModel::get_input_masks() in forms_model.php.

gform_input_mask_script

gform_input_mask_script

DescriptionUsageParametersExamplesPlacementSource Code

Description

Use this filter to change the initialization script for the input mask script. Can be used to specify different initialization parameters.

Usage

add_filter( 'gform_input_mask_script', 'set_mask_script', 10, 4 );

To target a specific form append the form id to the hook name. (format: gform_input_mask_script_FORMID)

add_filter( 'gform_input_mask_script_6', 'set_mask_script', 10, 4 );

Parameters

$script stringThe script to be filtered.

$script = "jQuery('#input_{$form['id']}_{$field->id}').mask('" . esc_js( $mask ) . "').on('keypress', function(e){if(e.which == 13){jQuery(this).blur();} } );";

$form_id integerID of current form.$field_id integerID of current field.$mask stringCurrently configured mask retrieved from $field->inputMaskValue.

Examples

This example changes the placeholder character to a blank space (」 「)

add_filter( 'gform_input_mask_script_185', 'set_mask_script', 10, 4 );function set_mask_script( $script, $form_id, $field_id, $mask ) {    $script = "jQuery('#input_{$form_id}_{$field_id}').mask('" . esc_js( $mask ) . "',{placeholder:' '}).on('keypress', function(e){if(e.which == 13){jQuery(this).blur();} } );";      return $script;}

A full list of available initialization options can be found at:

https://github.com/digitalBush/jquery.maskedinput

Placement

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

Source Code

gf_apply_filters( 'gform_input_mask_script', $form['id'], $script, $form['id'], $field->id, $mask );

This filter is located in GFFormDisplay::get_input_mask_init_script() in form_display.php

gform_input_change

gform_input_change

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
This JavaScript hook allows further actions to be performed when the keyup or change event is fired for an HTML input. The action only fires when the form is an AJAX form or has one of the following:

Calculation
CAPTCHA Field
Checkbox Field
Conditional Logic
Credit Card Field
Drop Down or Multi Select Field with the Enable enhanced user interface turned on
File Upload Field
JavaScript Merge Tags
List Field
Number Field Set to Currency
Page Field
Password Field with Enable Password Strength turned on
Price Field
Repeater Field

Usage
gform.addAction( 'gform_input_change', function( elem, formId, fieldId ) {
//do something
}, 10, 3 );

Parameters

elem
Window object.

formId
The ID of the current form.

fieldId
The field ID of the current field.

Examples
The example below can be found in Gravity Forms in the file js/conditional_logic.js .
gform.addAction( 'gform_input_change', function( elem, formId, fieldId ) {
if( ! window.gf_form_conditional_logic ) {
return;
}
var dependentFieldIds = rgars( gf_form_conditional_logic, [ formId, 'fields', gformExtractFieldId( fieldId ) ].join( '/' ) );
if( dependentFieldIds ) {
gf_apply_rules( formId, dependentFieldIds );
}
}, 10 );

Placement
Your code snippet can be placed in a HTML field on your form or in a theme custom JavaScript file.
Since
This filter was added in Gravity Forms version 1.9.14.
Source Code
This action hook is located in the function gf_input_change in js/gravityforms.js .

gform_init_scripts_footer

gform_init_scripts_footer

DescriptionUsagePlacementSource Code

Description
This filter is executed during form load. When set to true, the form init scripts are loaded in the footer of the site, instead of the default location of which is in the page body immediately after the form.
Note: This filter does not occur when AJAX is being used within the form.
Note: As of Gravity Forms 2.5 scripts are included in the footer by default.
Usage
add_filter( 'gform_init_scripts_footer', '__return_true' );

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

gform_incomplete_submissions_expiration_days

gform_incomplete_submissions_expiration_days

DescriptionUsageParametersExamplePlacementSource Code

Description
Overrides the number of days until incomplete submissions are purged.
Note: Using this filter does not change the value displayed in the save and continue confirmation message. You would need to manually update the confirmation message in the Form Settings > Confirmations area of the form in question.
Usage
add_filter( 'gform_incomplete_submissions_expiration_days', 'your_function_name' );

Parameters

$expiration_days int
The number of days until expiration. Defaults to 30.

Example
add_filter( 'gform_incomplete_submissions_expiration_days', 'change_incomplete_submissions_expiration_days' );
function change_incomplete_submissions_expiration_days( $expiration_days ) {
$expiration_days = 90;
return $expiration_days;
}

Placement
This code should be placed in the functions.php file of your active theme or within its own plugin.
Source Code
This filter is located in forms_model.php.

gform_incomplete_submission_pre_save

gform_incomplete_submission_pre_save

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Allows the draft submission for Save and Continue to be overridden before saved to the database.
Usage
1add_filter( 'gform_incomplete_submission_pre_save', 'your_function_name', 10, 3 );

Parameters

$submission_json array
JSON encoded associative array containing the incomplete submission. The following is found in the array:
123456*    @type array      $submitted_values The submitted values.*    @type array      $partial_entry    The draft entry created from the submitted values.*    @type null|array $field_values     The dynamic population field values.*    @type int        $page_number      The forms current page number.*    @type array      $files            The uploaded file properties.*    @type string     $gform_unique_id  The unique id for this submission.

$resume_token string
The unique token which can be used to resume the incomplete submission at a later date/time.

$form Form Object
The form object.

Examples
12345678add_filter( 'gform_incomplete_submission_pre_save', 'modify_incomplete_submission', 10, 3 );function modify_incomplete_submission( $submission_json, $resume_token, $form){    //change the user first name to Test in the saved data    $updated_json = json_decode( $submission_json );    $updated_json->submitted_values->{'1'}->{'1.3'} = 'Test';    $submission_json = json_encode($updated_json);    return $submission_json;}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms 2.3.4.
Source Code
This filter is located in GFFormsModel::filter_draft_submission_pre_save() in forms_model.php.

gform_incomplete_submission_post_save

gform_incomplete_submission_post_save

DescriptionUsageParametersExamples1. Basic usage2. Trigger Mailchimp feed3. Save token to current userSource Code

Description
Triggered after an incomplete form submission is saved.
Usage
add_action( 'gform_incomplete_submission_post_save', 'my_function', 10, 4 );

Parameters

$submission array
The submission data that was submitted.

$resume_token string
Resume token that is being used for this partial entry.

$form array
Contains an array of information regarding the form.

$entry array
Contains the partial entry that was created.

Examples
1. Basic usage
function my_function($submission, $resume_token, $form, $entry) {
//Do something here
}
add_action( 'gform_incomplete_submission_post_save', 'my_function', 10, 4 );

2. Trigger Mailchimp feed
This example shows how you can trigger the processing of a specific feed when an incomplete submission is saved.
add_action( 'gform_incomplete_submission_post_save', function ( $submission, $resume_token, $form, $entry ) {
if ( function_exists( 'gf_mailchimp' ) ) {
$feed = gf_mailchimp()->get_feed( '40' );
if ( ! empty( $feed ) ) {
gf_mailchimp()->process_feed( $feed, $entry, $form );
}
}
}, 10, 4 );

3. Save token to current user
This example shows how you can the resume token to the currently logged in users profile when an incomplete submission is saved.
add_action( 'gform_incomplete_submission_post_save', function ( $submission, $resume_token, $form, $entry ) {
if ( is_user_logged_in () ) {
update_user_meta( get_current_user_id(), '_gf_resume_token', $resume_token );
}
}, 10, 4 );

Source Code
This action hook is located in forms_model.php.

gform_incomplete_submission_post_get

gform_incomplete_submission_post_get

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Allows the draft submission for Save and Continue to be overridden after it is retrieved from the database but before it used to populate the form.
Usage
1add_filter( 'gform_incomplete_submission_post_get', 'your_function_name', 10, 3 );

Parameters

$submission_json array
JSON encoded associative array containing the incomplete submission. The following is found in the array:
123456*    @type array      $submitted_values The submitted values.*    @type array      $partial_entry    The draft entry created from the submitted values.*    @type null|array $field_values     The dynamic population field values.*    @type int        $page_number      The forms current page number.*    @type array      $files            The uploaded file properties.*    @type string     $gform_unique_id  The unique id for this submission.

$resume_token string
The unique token which can be used to resume the incomplete submission at a later date/time.

$form Form Object
The form object.

Examples
12345678add_filter( 'gform_incomplete_submission_post_get', 'modify_incomplete_submission_after', 10, 3 );function modify_incomplete_submission_after( $submission_json, $resume_token, $form){    //change the user first name to Test in the saved data    $updated_json = json_decode( $submission_json );    $updated_json->submitted_values->{'1'}->{'1.3'} = 'Test';    $submission_json = json_encode($updated_json);    return $submission_json;}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms 2.3.4.
Source Code
This filter is located in GFFormsModel::filter_draft_submission_post_get() in forms_model.php.