gform_web_api_capability_delete_entries

gform_web_api_capability_delete_entries

DescriptionUsageParametersExampleSource Code

Description
Filters the capability required to delete entries via the web API.
Usage
1add_filter( 'gform_web_api_capability_delete_entries', function ( $capability ) { return 'my_custom_capability'; } );

Parameters

$capability string
The capability required. Defaults to 『gravityforms_delete_entries』.

Example
1add_filter( 'gform_web_api_capability_delete_entries', function ( $capability ) { return 'my_custom_capability'; } );
Source Code
This action hook is located in webapi.php

gform_visibility_options

gform_visibility_options

DescriptionUsageParametersExamplesSource Code

Description
The 「gform_visibility_options」 filter in Gravity Forms allows default visibility options to be modified or removed and custom visibility options to be added.
Usage
1add_filter( 'gform_visibility_options', 'my_function', 10 );

Parameters

$options array
An array of visibility options.

$label string
The label of the visibility option; displayed in the field』s Visibility setting.

$value string
The value of the visibility option; will be saved to the form meta.

$description string
The description of the visibility option; used in the Visibility setting tooltip.

Examples
123456789add_filter( 'gform_visibility_options', 'my_custom_visibility_options' );function my_custom_visibility_options( $options ) {    $options[] = array(        'label'       => __( 'Custom Option' ),        'value'       => 'custom',        'description' => __( 'This is a description of my custom visibility option. It will show up in the Visibility setting tooltip.' )    );    return $options;}
Source Code
1return (array) apply_filters( 'gform_visibility_options', $options );
This hook is located in GFCommon::get_visibility_options() in common.php

gform_view

gform_view

DescriptionUsageParametersExamplePlacementSource Code

Description
The 「gform_view」 action allows additional actions to be performed based on the form view. Some form views that are used are 「entries」, 「entry」, 「notification」, and 「settings」.
Usage
add_action( 'gform_view', 'your_function_name' );

Parameters

$view string
The current view.

$id string
The form ID being viewed.

Example
add_action( 'gform_view', 'your_function_name' );

function your_function_name() {
// Do something
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This filter is located in gravityforms.php.

gform_validation

gform_validation

DescriptionUsageParametersExamples1. Validate a specific field2. Send entry data to third-party3. Abort Submission if Total is ZeroPlacementSource Code

Description

The 「gform_validation」 filter allows custom validation logic to be used by Gravity Forms when a form is submitted.

Usage

Applies to all forms.

add_filter( 'gform_validation', 'custom_validation' );

You can also specify this per form by adding the form id after the hook name.

add_filter( 'gform_validation_6', 'custom_validation' );

Note: DO NOT use the form specific version of this filter with forms that also have payment add-on feeds. If you need the validation to occur before the payment add-on validation use the generic version of the filter above and perform the form id check within the hooked function.

For an exhaustive walk-through on using the gform_validation hook, see Using the Gravity Forms 「gform_validation」 Hook.

Parameters

$validation_result array
Contains the validation result and the current Form Object.

Examples

1. Validate a specific field

This example uses the gform_validation filter to prevent a specific number from being entered in a field. In most cases the gform_field_validation() filter may be the better choice when validating a specific field.

add_filter( 'gform_validation', 'custom_validation' );
function custom_validation( $validation_result ) {
$form = $validation_result['form'];

//supposing we don't want input 1 to be a value of 86
if ( rgpost( 'input_1' ) == 86 ) {

// set the form validation to false
$validation_result['is_valid'] = false;

//finding Field with ID of 1 and marking it as failed validation
foreach( $form['fields'] as &$field ) {

//NOTE: replace 1 with the field you would like to validate
if ( $field->id == '1' ) {
$field->failed_validation = true;
$field->validation_message = 'This field is invalid!';
break;
}
}

}

//Assign modified $form object back to the validation result
$validation_result['form'] = $form;
return $validation_result;

}

2. Send entry data to third-party

This example demonstrates a simple approach to posting submitted entry data to a third party application. You can use the response to determine the form validation result.

add_filter( 'gform_validation', 'post_to_third_party' );
function post_to_third_party( $validation_result ) {

$form = $validation_result['form'];
$entry = GFFormsModel::get_current_lead();

$post_url = 'http://thirdparty.com';
$body = array(
'first_name' => rgar( $entry, '1.3' ),
'last_name' => rgar( $entry, '1.6' ),
'message' => rgar( $entry, '3' ),
);
GFCommon::log_debug( 'gform_validation: body => ' . print_r( $body, true ) );

$request = new WP_Http();
$response = $request->post( $post_url, array( 'body' => $body ) );
GFCommon::log_debug( 'gform_validation: response => ' . print_r( $response, true ) );

if ( /* check something in the $response */ ) {
// validation failed
$validation_result['is_valid'] = false;

//finding Field with ID of 1 and marking it as failed validation
foreach ( $form['fields'] as &$field ) {

//NOTE: replace 1 with the field you would like to validate
if ( $field->id == '1' ) {
$field->failed_validation = true;
$field->validation_message = 'This field is invalid!';
// Assuming both inputs of your name field failed the validation.
$field->set_input_validation_state( 1, false ); // Only for Gravity Forms 2.5.10 or higher.
$field->set_input_validation_state( 3, false ); // Only for Gravity Forms 2.5.10 or higher.
break;
}
}
}

//Assign modified $form object back to the validation result
$validation_result['form'] = $form;

return $validation_result;
}

3. Abort Submission if Total is Zero

This example will prevent the form submission if the Total field (id 3) is equal to zero.

add_filter( 'gform_validation', 'gf_fail_for_total_zero' );
function gf_fail_for_total_zero( $validation_result ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );
$form = $validation_result['form'];

// Change 3 to the id number of your Total field.
if ( empty( rgpost( 'input_3' ) ) ) {
GFCommon::log_debug( __METHOD__ . '(): Total field is empty.' );
// Set the form validation to false.
$validation_result['is_valid'] = false;
// Find Total field, set failed validation and message.
foreach ( $form['fields'] as &$field ) {
if ( $field->type == 'total' ) {
$field->failed_validation = true;
$field->validation_message = 'You must select at least one product!';
break;
}
}
}

// Assign modified $form object back to the validation result.
$validation_result['form'] = $form;
return $validation_result;
}

Placement

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

Source Code

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

gform_validation_message

gform_validation_message

DescriptionUsageParametersExamples1. Include form title in message2. Include field validation errorsPlacementSource Code

Description
This filter is executed when a form fails validation, before the validation message is displayed. Use this filter to change the default validation message.
Usage
Applies to all forms.
add_filter( 'gform_validation_message', 'your_function_name', 10, 2 );

To limit the scope of your function to a specific form, append the form id to the end of the hook name. (format: gform_validation_message_FORMID)
add_filter( 'gform_validation_message_5', 'your_function_name', 10, 2 );

Parameters

$message string
The validation message to be filtered.
"

" . esc_html__( 'There was a problem with your submission.', 'gravityforms' ) . ' ' . esc_html__( 'Errors have been highlighted below.', 'gravityforms' ) . '

'

$form Form Object
The current form.

Examples
1. Include form title in message
This example uses the gform_validation_message filter to change the default validation message.
add_filter( 'gform_validation_message', 'change_message', 10, 2 );
function change_message( $message, $form ) {
return "

Failed Validation - " . $form['title'] . '

';
}

2. Include field validation errors
add_filter( 'gform_validation_message', function ( $message, $form ) {
if ( gf_upgrade()->get_submissions_block() ) {
return $message;
}

$message = "

There was a problem with your submission. Errors have been highlighted below.

";
$message .= '

    ';

    foreach ( $form['fields'] as $field ) {
    if ( $field->failed_validation ) {
    $message .= sprintf( '

  • %s - %s
  • ', GFCommon::get_label( $field ), $field->validation_message );
    }
    }

    $message .= '

';

return $message;
}, 10, 2 );

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_validation_error_form_editor

gform_validation_error_form_editor

DescriptionUsageParametersExamplePlacementSource Code

Description
The 「gform_validation_error_form_editor」 is a Javascript filter that allows the form editor validation error to be overridden.
Usage
12345gform.addFilter( 'gform_validation_error_form_editor', function( error, form, has_product, has_option ) {    // do stuff     return error;} );

Parameters

error string
The error message.

form Form Object
The Form Object.

has_product boolean
Indicates if the current form has a product field.

has_option boolean
Indicates if the current form has a option field.

Example
This example prevents the form from being saved if there is a product field present.
This example uses the gform_admin_pre_render filter to load the hook on the form editor page:
1234567891011121314add_filter( 'gform_admin_pre_render', function ( $form ) {    echo GFCommon::is_form_editor() ? "        " : '';     //return the form object from the php hook    return $form;} );
Placement
This code should be placed in the functions.php file of your active theme within the gform_admin_pre_render hook.
Source Code
This filter is located in js.php.

gform_userregistration_feed_settings_fields

gform_userregistration_feed_settings_fields

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
This filter can be used to modify the setting fields that appear on the feed page.
Usage
1add_filter( 'gform_userregistration_feed_settings_fields', 'your_function_name', 10, 2 );

Parameters

$fields array
An array of fields, with the name property corresponding with the property which appears in the User Registration Feed Meta. See the Settings API for more details.

$form Form Object
The form currently being processed.

Examples
1234567891011121314151617181920212223add_filter( 'gform_userregistration_feed_settings_fields', 'add_custom_user_registration_setting', 10, 2 );function add_custom_user_registration_setting( $fields, $form ) {    // adding my custom setting to the Additional Settings section    $fields['additional_settings']['fields'][] = array(        'name'      => 'myCustomSetting',        'label'     => __( 'My Custom Setting', 'my-text-domain' ),        'type'      => 'checkbox',        'choices'   => array(            array(                'label'         => __( 'This is the checkbox label', 'my-text-domain' ),                'value'         => 1,                'name'          => 'myCustomSetting'            )        ),        'tooltip' => sprintf( '

%s

%s', __( 'Tooltip Header', 'my-text-domain' ), __( 'This is the tooltip description', 'my-text-domain' ) ),        // this setting should only be visible for "create" feeds (and not "update" feeds)        'dependency'  => array(            'field'   => 'feedType',            'values'  => 'create'        )    );    return $fields;}
Placement
Your code snippet should be placed in the functions.php file of your active theme.
Since
This filter was added in version 3.0.
Source Code
1$fields = apply_filters( 'gform_userregistration_feed_settings_fields', $fields, $form );
This filter is located in GF_User_Registration::feed_settings_fields() in class-gf-user-registration.php.

gform_userregistration_delete_signup

gform_userregistration_delete_signup

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
The action gform_userregistration_delete_signup allows custom actions to be performed when pending activations are deleted.
Usage
1add_action( 'gform_userregistration_delete_signup', 'your_function_name' );

Parameters

$signup object
Object of signup information

Examples
12345678add_action( 'gform_userregistration_delete_signup', 'save_data_in_delete_table' ); function save_data_in_delete_table ( $signup ){    //save data into a deletion table if not admin signup    if ( $signup->user_login != 'admin' ){        //insert into table    }}
Placement
This code should be placed in the functions.php file of your active theme.
Since
This action was added in User Registration version 3.0.
Source Code
This action is located in GFUserSignups::delete_signup() in includes/signups.php.

gform_userregistration_associate_entry_with_user

gform_userregistration_associate_entry_with_user

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
Used to determine if the entry should be associated with newly created user.
Usage
add_filter( 'gform_userregistration_associate_entry_with_user', 'your_function_name', 10, 5 );

Parameters

$update_entry_creator bool
If entry creator should be associated with user.

$user_id int
New user ID.

$feed Feed Object
The current feed.

$entry Entry Object
The current entry.

$form Form Object
The current form.

Examples
add_filter( 'gform_userregistration_associate_entry_with_user', 'associate_entry', 10, 5 );
function associate_entry( $update_entry_creator, $user_id, $feed, $entry, $form ){
return true;
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in User Registration version 4.0.9.
Source Code
This filter is located in GF_User_Registration::create_user() in gravityformsuserregistration/class-gf-user-registration.php.

gform_username

gform_username

DescriptionUsageParametersExamplesPlacementSource Code

Description
This filter is used to dynamically alter or generate a username during the registration process.
Usage
The base filter which would run for all forms would be used like so:
add_filter( 'gform_username', 'your_function_name', 10, 4 );

To target a specific form append the form id to the hook name. (format: gform_username_FORMID)
add_filter( 'gform_username_4', 'your_function_name', 10, 4 );

Parameters

$username string
The value of the username as submitted by the user.

$feed Feed Object
The Feed which is currently being processed.

$form Form Object
The current form object.

$entry Entry Object
The current entry object.

Examples
This example retrieves the first and last name values of a Name field, combines them without spaces or special characters, and assigns that value as the username. It checks if that username exists and if so, appends an integer to the username (i.e., 2, 3, 4) until it finds a username plus integer combination that does not yet exist.
To use this example you need to update the inputs id numbers with the correct values for your name field, and update the filter name to use your form id number. Check the comment in the snippet.
// Change 8 in gform_username_8 to your form id number.
add_filter( 'gform_username_8', 'auto_username', 10, 4 );
function auto_username( $username, $feed, $form, $entry ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );
// Update 2.3 and 2.6 with the id numbers of your Name field inputs. e.g. If your Name field has id 1 the inputs would be 1.3 and 1.6
$username = strtolower( rgar( $entry, '2.3' ) . rgar( $entry, '2.6' ) );

if ( empty( $username ) ) {
GFCommon::log_debug( __METHOD__ . '(): Value for username is empty.' );
return $username;
}

if ( ! function_exists( 'username_exists' ) ) {
require_once( ABSPATH . WPINC . '/registration.php' );
}

if ( username_exists( $username ) ) {
GFCommon::log_debug( __METHOD__ . '(): Username already exists, generating a new one.' );
$i = 2;
while ( username_exists( $username . $i ) ) {
$i++;
}
$username = $username . $i;
GFCommon::log_debug( __METHOD__ . '(): New username: ' . $username );
};

return $username;
}

Placement
This code should be placed in the functions.php file of your active theme.
Source Code
$username = gf_apply_filters( 'gform_username', $form['id'], $username, $feed, $form, $entry );

This filter is located in GF_User_Registration::validate() and GF_User_Registration::get_user_data() in class-gf-user-registration.php.