gform_addon_field_value

gform_addon_field_value

DescriptionUsageParametersExamples1. Change Value of Specific Field2. Use Choice Text Instead of ValuePlacementSource CodeSince

Description
This filter can be used to modify a value before it is sent to a third-party by one of the Add-On Framework based add-ons. If you want to filter the value for a specific add-on you can use gform_short_slug_field_value.
Usage
The base filter which would run for all forms and all fields would be used like so:
add_filter( 'gform_addon_field_value', 'your_function_name', 10, 5 );

To target a specific form append the form id to the hook name. (format: gform_addon_field_value_FORMID)
add_filter( 'gform_addon_field_value_10', 'your_function_name', 10, 5 );

To target a specific field append both the form id and the field id to the hook name. (format: gform_addon_field_value_FORMID_FIELDID)
add_filter( 'gform_addon_field_value_10_3', 'your_function_name', 10, 5 );

Parameters

$field_value string
The value to be modified.

$form Form Object
The form currently being processed.

$entry Entry Object
The entry currently being processed.

$field_id string
The id of the field currently being processed.

$slug string
The add-on slug, including the gravityforms prefix. See the Gravity Forms Add-On Slugs article for a list of possible slugs.

Examples
1. Change Value of Specific Field
This example shows how you can change the value of field 3 on form 10 before it is passed to any of the feed add-ons.
add_filter( 'gform_addon_field_value_10_3', function ( $field_value, $form, $entry, $field_id ) {

return 'your new value';
}, 10, 4 );

2. Use Choice Text Instead of Value
This example shows how you can replace the value of a choice based survey field with the choice text.
add_filter( 'gform_addon_field_value', 'gf_get_choice_text', 10, 5 );
function gf_get_choice_text( $field_value, $form, $entry, $field_id, $slug ) {
$field = RGFormsModel::get_field( $form, $field_id );

if ( is_object( $field ) && $field->type == 'survey' ) {
$field_value = $field->get_value_export( $entry, $field_id, true );
}

return $field_value;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
$field_value = gf_apply_filters( array( 'gform_addon_field_value', $form['id'], $field_id ), $field_value, $form, $entry, $field_id, $this->_slug );

This filter is located in GFAddOn::get_field_value() in includes/addon/class-gf-addon.php.
Since
This filter was added in Gravity Forms 1.9.15.12.

gform_addon_navigation

gform_addon_navigation

DescriptionUsageParametersExamplesSource Code

Description
Use this filter to add a sub-menu item under the 「Forms」 menu.
Usage
1add_filter( 'gform_addon_navigation', 'add_menu_item' );
Parameters

$menu_items array
Current list of menu items to be filtered, in the following format:
123456array(    array(  "name" => "gf_campaignmonitor",        "label" => "Campaign Monitor",        "callback" => "campaignmonitor_page",        "permission" => "gravityforms_campaignmonitor"););

Examples
This example adds a new sub-menu item under 「Forms」.
12345add_filter( 'gform_addon_navigation', 'add_menu_item' );function add_menu_item( $menu_items ) {    $menu_items[] = array( "name" => "new_submenu_name", "label" => "New Submenu", "callback" => "submenu_handler", "permission" => "edit_posts" );    return $menu_items;}
Source Code
This filter is located in GFForms::create_menu() in gravityforms.php

gform_addon_pre_process_feeds

gform_addon_pre_process_feeds

DescriptionUsageParametersExamples1. Convert User Registration 「Create」 Feeds to 「Update」 Feeds if User is Logged-in2. Override the User Registration Role Setting3. Override Mailchimp Feed SettingPlacementSource CodeSince

Description
Modify all possible feeds before they are processed by Gravity Forms.
Usage
Generic: applies to feeds for all add-ons and all forms.
1add_filter( 'gform_addon_pre_process_feeds', 'your_function_name', 10, 3 );
Generic, Form-specific: applies to feeds for all add-ons for a specific form.
1add_filter( 'gform_addon_pre_process_feeds_{FORM_ID}', 'your_function_name' );
Addon-specific: applies to feeds for a specific add-on for all forms.
1add_filter( 'gform_{ADDON_SLUG}_pre_process_feeds', 'your_function_name', 10, 3 );
See the Gravity Forms Add-On Slugs article for a list of possible slugs.
Addon-specific, Form-specific: applies to feeds for a specific add-on and form.
1add_filter( 'gform_{ADDON_SLUG}_pre_process_feeds_{FORM_ID}', 'your_function_name' );

Parameters

$feeds array
An array of Feed Objects.

$entry Entry Object
Current entry for which $feeds will be processed.

$form Form Object
Current form object.

Examples
1. Convert User Registration 「Create」 Feeds to 「Update」 Feeds if User is Logged-in
12345678910add_filter( 'gform_gravityformsuserregistration_pre_process_feeds', function( $feeds ) {     if ( is_user_logged_in() && is_array( $feeds ) ) {        foreach( $feeds as &$feed ) {            $feed['meta']['feedType'] = 'update';        }    }     return $feeds;} );
2. Override the User Registration Role Setting
This example shows how the choice selected for the User Registration feed of form 2 can be overridden with the value of a form field during form submission. The form field choices would need to be configured with the roles.
12345678add_filter( 'gform_gravityformsuserregistration_pre_process_feeds_2', function ( $feeds, $entry ) {    foreach ( $feeds as &$feed ) {        // use the value submitted for field 5 as the role        $feed['meta']['role'] = rgar( $entry, '5' );    }     return $feeds;}, 10, 2 );
3. Override Mailchimp Feed Setting
This example shows how you can override a setting on a Mailchimp feed. See the Mailchimp Feed Meta article for the available settings.
1234567add_filter( 'gform_gravityformsmailchimp_pre_process_feeds', function ( $feeds, $entry ) {    foreach ( $feeds as &$feed ) {        $feed['meta']['double_optin'] = false;    }     return $feeds;}, 10, 2 );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in /includes/addon/class-gf-feed-addon.php.
Since
This filter was added in Gravity Forms 2.0-beta-2.

gform_address_city

gform_address_city

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter is executed when creating the address city field and can be used to modify the 「City」 label.
Usage
Applies to all forms.
1add_filter( 'gform_address_city', 'change_address_city', 10, 2 );
Applies to a specific form. In this case, form id 5.
1add_filter( 'gform_address_city_5', 'change_address_city', 10, 2 );
Parameters

$label string
The label to be filtered.

$form_id integer
The current form』s id.

Examples
This example changes the default address city label:
1234add_filter( 'gform_address_city', 'change_address_city', 10, 2 );function change_address_city( $label, $form_id ) {    return "Town";}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in js.php and GF_Field_Address::get_field_input() in includes/fields/class-gf-field-address.php.

gform_address_country

gform_address_country

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter is executed when creating the address country field and can be used to modify the 「Country」 label.
Usage
Applies to all forms.
1add_filter( 'gform_address_country', 'change_address_country', 10, 2 );
Applies to a specific form. In this case, form id 5.
1add_filter( 'gform_address_country_5', 'change_address_country', 10, 2 );
Parameters

$label string
The label to be filtered.

$form_id
The current form』s id.

Examples
This example changes the default address country label:
1234add_filter( 'gform_address_country', 'change_address_country', 10, 2 );function change_address_country( $label, $form_id ) {    return "Address Country";}
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in js.php and GF_Field_Address::get_field_input() in includes/fields/class-gf-field-address.php.

gform_address_display_format

gform_address_display_format

DescriptionUsageParametersExamplesSinceSource Code

Description
This filter can be used to change the way addresses are formatted.
Usage
add_filter( 'gform_address_display_format', 'change_address', 10, 2 );

Parameters

$format string
The format to be filtered.
Possible values: default and zip_before_city.

default
Addresses are formatted in the following order: Street, Street2, City, State, Zip Code, Country.

zip_before_city
Addresses are formatted in the following order: Street, Street2, Zip, City, State, Country.

$field Field Object
The current field.

Examples
This example demonstrates how to change the address format to zip_before_city.
add_filter( 'gform_address_display_format', 'address_format', 10, 2 );
function address_format( $format, $field ) {
return 'zip_before_city';
}

Since
This filter was added in Gravity Forms version 1.5.28.
Added $field parameter in 1.9.2.
Source Code
This filter is located in the following methods in includes/fields/class-gf-field-address.php:

GF_Field_Address::get_field_input()
GF_Field_Address::get_value_entry_detail()

gform_address_state

gform_address_state

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter is executed when creating the address state field and can be used to modify the 「State」 label.
Usage
Applies to all forms.
add_filter( 'gform_address_state', 'change_address_state', 10, 2 );

Applies to a specific form. In this case, form id 5.
add_filter( 'gform_address_state_5', 'change_address_state', 10, 2 );

Parameters

$label string
The label to be filtered.

$form_id integer
The current form』s id.

Examples
This example changes the default address state label:
add_filter( 'gform_address_state', 'change_address_state', 10, 2 );
function change_address_state( $label, $form_id ) {
return "Address State";
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in js.php and GF_Field_Address::get_field_input() in includes/fields/class-gf-field-address.php.

GF_Field_Total

GF_Field_Total

IntroductionSettings and PropertiesSettingsPropertiesSource Code

Introduction
The GF_Field_Total class extends the GF_Field class, also known as the Field Object. This class is responsible for determining how the Total field is rendered when the form is displayed and how its value is handled during and after form submission.
Settings and Properties
Settings control what options are available to the admin user when configuring the field in the form editor. Gravity Forms includes many built-in settings such as Field Label, Field Description, Choices, Conditional Logic, etc. In addition to built-in settings, custom settings can also be developed. For more information on how to develop custom settings and how to associate settings to a field, visit the GF_Field page.
Properties contain the values specified by the settings and generally are part of the Field Object.
The properties may be retrieved by accessing the Field Object as follows:
12345//get the field$field = GFFormsModel::get_field( $form, 1 ); //get the admin label$admin_label = $field->adminLabel;
Settings
The following settings are available for the field:

admin_label_setting
Controls whether the 「Admin Field Label」 setting appears.

conditional_logic_field_setting
Controls whether the 「Enable Conditional Logic」 setting appears.

css_class_setting
Controls whether the 「Custom CSS Class」 setting displays. This allows a custom css to be used for the field.

description_setting
Controls whether the 「Description」 setting appears. This allows a description for the field to be displayed.

label_setting
Controls whether the 「Field Label」 setting which allows the label to be changed appears.

Properties
Below is a listing of the properties inherited from the parent class and ones specific to the field.

adminLabel string
The label to be used on admin pages instead of the label, useful for fields with long labels.

conditionalLogic array
An associative array containing the conditional logic rules. See the Conditional Logic Object for more details.

cssClass string
The custom CSS class or classes to be added to the input tag for the field.

description string
The field description.

descriptionPlacement string
The placement of the field description. The description may be placed 「above」 or 「below」 the field inputs. If the placement is not specified, then the description placement setting for the Form Layout is used.

formId integer
The form ID.

id integer
The field ID.

type string
The field type, which in this case is total.

Source Code
The source code is located in includes/fields/class-gf-field-total.php in the Gravity Forms folder of your sites plugins directory.

GF_Field_Website

GF_Field_Website

IntroductionSettings and PropertiesSettingsPropertiesSource Code

Introduction
The GF_Field_Website class extends the GF_Field class, also known as the Field Object. This class is responsible for determining how the website field is rendered when the form is displayed and how its value is handled during and after form submission.
Settings and Properties
Settings control what options are available to the admin user when configuring the field in the form editor. Gravity Forms includes many built-in settings such as Field Label, Field Description, Choices, Conditional Logic, etc. In addition to built-in settings, custom settings can also be developed. For more information on how to develop custom settings and how to associate settings to a field, visit the GF_Field page.
Properties contain the values specified by the settings and generally are part of the Field Object.
The properties may be retrieved by accessing the Field Object as follows:
12345//get the field$field = GFFormsModel::get_field( $form, 1 ); //get the admin label$admin_label = $field->adminLabel;
Settings
The following settings are available for the field:

admin_label_setting
Controls whether the 「Admin Field Label」 setting appears.

conditional_logic_field_setting
Controls whether the 「Enable Conditional Logic」 setting appears.

css_class_setting
Controls whether the 「Custom CSS Class」 setting displays. This allows a custom css to be used for the field.

default_value_setting
Controls whether the 「Default Values」 section displays. This allows a value to be set for the field.

description_setting
Controls whether the 「Description」 setting appears. This allows a description for the field to be displayed.

duplicate_setting
Controls whether the 「No Duplicates」 setting displays within the 「Rules」 section. This controls whether the same value may exist more than once in the database. The 「Rules」 setting must be active for this to display.

error_message_setting
Controls whether the 「Custom Validation Message」 setting which allows a custom message to be used appears.

label_setting
Controls whether the 「Field Label」 setting which allows the label to be changed appears.

placeholder_setting
Controls whether the 「Placeholders」 section appears. This allows placeholder text to display for the field.

prepopulate_field_setting
Controls whether the 「Allow field to be populated dynamically」 setting appears.

rules_setting
Controls whether the 「Rules」 settings section displays. The 「Required」 option shows when this is active.

size_setting
Controls whether the 「Field Size」 setting displays. This controls the size of the input field for fields to which it applies. The sizes are 「small」, 「medium」, and 「large」.

visibility_setting
Controls whether the 「Visibility」 setting displays. The controls whether the option of visibility being for 「Everyone」 or 「Admin Only」 can be set.

Properties
Below is a listing of the properties inherited from the parent class. There are no properties unique to the Website field.

adminLabel string
The label to be used on admin pages instead of the label, useful for fields with long labels.

adminOnly boolean
Determines whether the field is visible to the user submitting the form, or only visible in the admin.

allowsPrepopulate boolean
Determines if the field values can be dynamically populated. Default is false.

conditionalLogic array
An associative array containing the conditional logic rules. See the Conditional Logic Object for more details.

cssClass string
The custom CSS class or classes to be added to the input tag for the field.

defaultValue string
The default value to be displayed in the input field.

description string
The field description.

descriptionPlacement string
The placement of the field description. The description may be placed 「above」 or 「below」 the field inputs. If the placement is not specified, then the description placement setting for the Form Layout is used.

errorMessage string
The custom error message to be displayed if the field fails validation.

formId integer
The form ID.

id integer
The field ID.

isRequired boolean
Marking the field as required will prevent the form from being submitted if the user does not enter a value. Default is false.

label string
The field label that will be displayed on the form and on the admin pages.

maxLength string
The number of characters that the field is allowed to contain.

noDuplicates boolean
Determines if the value entered by the user may already exist in the database.

placeholder string
Placeholder text to give the user a hint on how to fill out the field. This is not submitted with the form. For the website field, the text 「http://」 is displayed.

size string
Controls the width of the input field. The choices are 「small」, 「medium」, and 「large」.

type string
The field type, which in this case is website.

Source Code
The source code is located in includes/fields/class-gf-field-website.php in the Gravity Forms folder of your sites plugins directory.

GF_Field

GF_Field

IntroductionGetting StartedMain Functionalityget_form_editor_field_title()get_form_editor_button()get_form_editor_field_settings()is_conditional_logic_supported()get_field_input()get_field_content()validate()get_form_inline_script_on_page_render()get_form_editor_inline_script_on_page_render()get_value_save_entry()get_value_merge_tag()get_value_entry_detail()SanitizationInput SanitizationOutput SanitizationHelpersget_input_type()get_tabindex()get_conditional_logic_event()get_field_placeholder_attribute()get_input_placeholder_attribute()Core Field ClassesAdd-On Field Classes

Introduction

The GF_Field class provides basic functionality for developers when creating new fields for Gravity Forms. It facilitates the following:

Adding a button for the field to the form editorDefining the field title to be used in the form editorDefining which settings should be present when editing the fieldRegistering the field as compatible with conditional logicOutputting field scripts to the form editor and front-endDefining the field appearance on the front-end, in the form editor and on the entry detail pageValidating the field during submissionSaving the entry valueDefining how the entry value is displayed when merge tags are processed, on the entries list and entry detail pagesDefining how the entry value should be formatted when used in csv exports and by framework based add-ons

Getting Started

These are the first steps you』ll need to take to create a field using the Field Framework.

Creating a new class which extends GF_Field (Note: If your new field will have similar functionality to an existing field you can save some work by extending that field type instead e.g. GF_Field_Post_Image extends GF_Field_Fileupload)Add the $type variableRegister the field with Gravity Forms

Example:

123456class GF_Field_Phone extends GF_Field {     public $type = 'phone'; }GF_Fields::register( new GF_Field_Phone() );

Main Functionality

Now you have the basic field you can start defining its appearance and behaviour by overriding functions from GF_Field or whichever the class you extended.

The examples shown below are taken from various field types.

get_form_editor_field_title()

The default behaviour of get_form_editor_field_title() is to return the value of the $type variable, however, you may want the field in the form editor to use a different title or have the first letter uppercased in which case you will want to override this method.

public function get_form_editor_field_title() {}

Example:

public function get_form_editor_field_title() {    return esc_attr__( 'Phone', 'gravityforms' );}

get_form_editor_button()

The default behaviour of get_form_editor_button() is to return an associative array assigning the field to the standard_fields group using the value returned by get_form_editor_field_title() as the button text.

The built-in groups are standard_fields, advanced_fields, post_fields, and pricing_fields. See the How To Add A Custom Field Group When Using The Field Framework article for an example showing how you can define a new group.

public function get_form_editor_button() {}

Example:

public function get_form_editor_button() {    return array(        'group' => 'advanced_fields',        'text'  => $this->get_form_editor_field_title()    );}

get_form_editor_field_settings()

The default behaviour of get_form_editor_field_settings() is to return an empty array so you will want to override this method and return an array containing the class names of the settings you want to appear on your field in the form editor.

You can find a list of the available settings in the following articles:

General Field SettingsAppearance Field SettingsAdvanced Field Settings

You can also define your own custom settings by using the gform_field_standard_settings, gform_field_appearance_settings, and gform_field_advanced_settings hooks.

function get_form_editor_field_settings() {}

Example:

function get_form_editor_field_settings() {    return array(        'conditional_logic_field_setting',        'prepopulate_field_setting',        'error_message_setting',        'label_setting',        'label_placement_setting',        'admin_label_setting',        'size_setting',        'rules_setting',        'visibility_setting',        'duplicate_setting',        'default_value_setting',        'placeholder_setting',        'description_setting',        'phone_format_setting',        'css_class_setting',    );}

is_conditional_logic_supported()

The default behaviour of is_conditional_logic_supported() is to return false meaning the field can』t be used with conditional logic. Override this method returning true to allow the field to be used when configuring conditional logic rules.

public function is_conditional_logic_supported() {}

Example:

public function is_conditional_logic_supported() {    return true;}

get_field_input()

This method is used to define the fields inner markup, including the div with the ginput_container class. The default behaviour of get_field_input() is to return an empty string so you will want to override this method.

public function get_field_input( $form, $value = '', $entry = null ) {}

Parameters:

$form Form ObjectThe form object currently being processed.$value string|arrayThe field value from the $_POST or the resumed incomplete submission.$entry null|Entry ObjectNull or the entry object currently being edited.

Return:

The field』s inner markup. string

Example:

public function get_field_input( $form, $value = '', $entry = null ) {    $form_id         = $form['id'];    $is_entry_detail = $this->is_entry_detail();    $id              = (int) $this->id;     if ( $is_entry_detail ) {        $input = "";         return $input . '
' . esc_html__( 'Coupon fields are not editable', 'gravityformscoupons' );    }     $disabled_text         = $this->is_form_editor() ? 'disabled="disabled"' : '';    $logic_event           = version_compare( GFForms::$version, '2.4.1', '<' ) ? $this->get_conditional_logic_event( 'change' ) : '';    $placeholder_attribute = $this->get_field_placeholder_attribute();    $coupons_detail        = rgpost( "gf_coupons_{$form_id}" );    $coupon_codes          = empty( $coupons_detail ) ? '' : rgpost( "input_{$id}" );     $input = "

" .             "get_tabindex() . '/>' .             "get_tabindex() . '/> ' .             "" .             "

" .             "" .             "" .             "" .             "

";     return $input;}

get_field_content()

This method is used to define the fields overall appearance, such as how the admin buttons, field label, description or validation messages are included. Most fields won』t need to override this method, display only types such as Page, Section or HTML are examples of fields which do override the get_field_content() method.

1public function get_field_content( $value, $force_frontend_label, $form ) {}

Parameters:

$value string|array
The field value from the $_POST or the resumed incomplete submission.

$force_frontend_label boolean
Should the frontend label be displayed in the admin even if an admin label is configured. Default is false.

$form Form Object
The form object currently being processed.

Return:
The fields markup. string. Note: use the placeholder {FIELD} to define where the markup returned by get_field_input() should be included.

Example:

public function get_field_content( $value, $force_frontend_label, $form ) {    $form_id         = $form['id'];    $admin_buttons   = $this->get_admin_buttons();    $is_entry_detail = $this->is_entry_detail();    $is_form_editor  = $this->is_form_editor();    $is_admin        = $is_entry_detail || $is_form_editor;    $field_label     = $this->get_field_label( $force_frontend_label, $value );    $field_id        = $is_admin || $form_id == 0 ? "input_{$this->id}" : 'input_' . $form_id . "_{$this->id}";    $field_content   = ! $is_admin ? '{FIELD}' : $field_content = sprintf( "%s{FIELD}", $admin_buttons, $field_id, esc_html( $field_label ) );     return $field_content;}

validate()

Override this method to perform custom validation logic. This method is only used if the field passes the required validation (field is not empty), and any no duplicates validation.

1public function validate( $value, $form ) {}

Parameters:

$value string|array
The field value from the $_POST.

$form Form Object
The form object currently being processed.

Return:
This method does not return a value via a return statement. Return the validation result and message by setting the fields failed_validation and validation_message properties.

Example:

public function validate( $value, $form ) {    $regex = '/^D?(d{3})D?D?(d{3})D?(d{4})$/';    if ( $this->phoneFormat == 'standard' && $value !== '' && $value !== 0 && ! preg_match( $regex, $value ) ) {        $this->failed_validation = true;        if ( ! empty( $this->errorMessage ) ) {            $this->validation_message = $this->errorMessage;        }    }}

get_form_inline_script_on_page_render()

Override this method to include scripts with the form init scripts on page render. The init scripts are usually included immediately after the form in the page body.

Note: