gform_freshbooks_args_pre_create

gform_freshbooks_args_pre_create

DescriptionUsageParametersExamples1. Add tax2. Set the line itemsPlacementSource Code

Description
This filter can be used to modify the invoice or estimate object before it is sent to Freshbooks.
Usage
The filter which would run for all Freshbooks feeds can be used like so:
add_filter( 'gform_freshbooks_args_pre_create', 'your_function_name', 10, 4 );

Parameters

$args object
The Freshbooks invoice or estimate object containing the client details, line items, etc.
$args->clientId = '';
$args->number = '';
$args->amount = '';
$args->status = '';
$args->date = '';
$args->poNumber = '';
$args->discount = '';
$args->notes = '';
$args->terms = '';
$args->organization = '';
$args->firstName = '';
$args->lastName = '';
$args->pStreet1 = '';
$args->pStreet2 = '';
$args->pCity = '';
$args->pState = '';
$args->pCountry = '';
$args->pCode = '';
$args->lines = array(
array(
'name' => '',
'description' => '',
'unitCost' => '',
'quantity' => '',
'amount' => '',
),
);

$form Form Object
The Form which is currently being processed.

$entry Entry Object
The Entry which is currently being processed.

$feed Feed Object
The Feed which is currently being processed. Available from v2.2.3.

Examples
1. Add tax
The following example shows how you can add tax to the line items.
add_filter( 'gform_freshbooks_args_pre_create', function ( $args, $form, $entry ) {
$lines = $args->lines;
foreach ( $lines as &$line ) {
$line['tax1Name'] = 'VAT';
$line['tax1Percent'] = 20;
}
$args->lines = $lines;

return $args;
}, 10, 3 );

2. Set the line items
The following example shows how you can set the invoice line items, including how a value can be retrieved from a form field.
add_filter( 'gform_freshbooks_args_pre_create', function ( $args, $form, $entry ) {
$lines = array();

$name = 'The name';
$description = 'The description';
$unit_cost = 10.50;
$quantity = rgar( $entry, '5' ); // get the value from field 5
$amount = $unit_cost * $quantity;

$lines[] = array(
'name' => $name,
'description' => $description,
'unitCost' => $unit_cost,
'quantity' => $quantity,
'amount' => $amount,
);

$args->lines = $lines;

return $args;
}, 10, 3 );

Placement
Your code snippet should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFFreshBooks::export_feed() in class-gf-freshbooks.php.

gform_forms_post_import

gform_forms_post_import

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Use this hook to perform actions after importing forms.
Usage
add_action( 'gform_forms_post_import', 'your_function_name' );

Parameters

$forms Form Object
An array of form objects.

Example
This example shows how you can display a message after importing forms.
add_action( 'gform_forms_post_import', 'my_action_gform_forms_post_import' );
function my_action_gform_forms_post_import( $forms ) {
GFCommon::add_message( 'Change the sample values' );
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This hook was added in Gravity Forms 1.9.13.29.
Source Code
do_action( 'gform_forms_post_import', $forms )
This action hook is located in GFExport::import_json() in export.php.

gform_format_option_label

gform_format_option_label

DescriptionUsageParametersExamplesRemove Price from LabelDisplay Price before LabelShow Option Price instead of Variable PricingPlacementSource Code

Description
This filter is executed when calculating and displaying the pricing on product option fields or shipping fields set as drop down field or radio buttons type. Use this filter to change the format of the choice labels for these field types.
Usage

Parameters

fullLabel string
The default label that will be displayed for the current option. It has the field choice label as well as the calculated price. (i.e. My Option +$5.00)

fieldLabel string
The field/option label without the price. (i.e. My Option)

priceLabel string
The price text without the field label. (i.e. +$5.00)

selectedPrice float
The price of the currently selected option.

price float
The price of this option. (The option that this label applies to)

formId integer
The current form ID.

fieldId integer
The current field ID.

Examples
Remove Price from Label
The following example disables the option pricing, displaying only the option label.

Display Price before Label
The following example changes the order of the labels, displaying the option price before the field label. I only does that for form ID 5.

Show Option Price instead of Variable Pricing
This example replaces the variable pricing with the static full option price for a field with id 43.

Placement
This code should be placed in an HTML field on your form or you may use the gform_pre_render hook to echo the script block to the page.
Source Code
This filter is located in gravityforms.js

gform_form_validation_errors

gform_form_validation_errors

DescriptionUsageParametersExamples1. Add a new errorPlacementSinceSource Code

Description
The gform_form_validation_errors filter enables the list of validation errors, which will be displayed at the top of the form, to be overridden.
Usage
add_filter( 'gform_form_validation_errors', 'your_function_name', 10, 2 );

You can also specify this per form by adding the form id after the filter name.
add_filter( 'gform_form_validation_errors_6', 'your_function_name', 10, 2 );

Parameters

$errors array
An array of field validation errors. The following keys will be defined for each error: field_label, field_selector, and message.

$form Form Object
The current form object.

Examples
1. Add a new error
add_filter( 'gform_form_validation_errors', function( $errors, $form ) {
$errors[] = array( 'field_label' => 'the field label here', 'field_selector' => '#field_1_10', 'message' => 'the error message here' );

return $errors;
}, 10, 2 );

Placement
This code should be placed in the functions.php file of your active theme or a custom functions plugin.
Since
This filter was added in Gravity Forms v2.5.
Source Code
This filter is located in GFFormDisplay::get_validation_errors() in form_display.php.

gform_form_validation_errors_markup

gform_form_validation_errors_markup

DescriptionUsageParametersExamples1. Basic usagePlacementSinceSource Code

Description
The gform_form_validation_errors_markup filter enables the markup for the validation errors list, which is located at the top of the form, to be overridden.
Usage
add_filter( 'gform_form_validation_errors_markup', 'your_function_name', 10, 2 );

You can also specify this per form by adding the form id after the filter name.
add_filter( 'gform_form_validation_errors_markup_6', 'your_function_name', 10, 2 );

Parameters

$validation_errors_markup string
The HTML for the validation errors list.

$form Form Object
The current form object.

Examples
1. Basic usage
add_filter( 'gform_form_validation_errors_markup', function( $validation_errors_markup, $form ) {
// Do something with the $validation_errors_markup.

return $validation_errors_markup;
}, 10, 2 );

Placement
This code should be placed in the functions.php file of your active theme or a custom functions plugin.
Since
This filter was added in Gravity Forms v2.5.
Source Code
This filter is located in GFFormDisplay::get_validation_errors_markup() in form_display.php.

gform_form_update_meta

gform_form_update_meta

DescriptionUsageParametersExamplePlacementSinceSource Code

Description
Allows modifying the form meta before it is saved to the database.
Usage
The following would apply to all forms:
add_filter( 'gform_form_update_meta', 'my_import_form', 10, 3 );

To target a specific form, append the form id to the hook name. (format: gform_form_update_meta_FORMID):
add_filter( 'gform_form_update_meta_1', 'my_import_form', 10, 3 );

Parameters

$form_meta bool
The meta data for the current form.

$form_id int
The current form ID.

$meta_name string
Meta name.

Example
add_filter( 'gform_form_update_meta', 'my_import_form', 10, 3 );
function my_import_form( $meta, $form_id, $meta_name ) {
$is_import_page = GFForms::get_page() == 'import_form';
$is_updating_display_meta = $meta_name == 'display_meta';
if( ! $is_import_page || ! $is_updating_display_meta )
return $meta;
$form = $meta;
$form['isImported'] = true;
return $form;
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 1.8.8.
Source Code
This filter is located in GFFormsModel::update_form_meta() in forms_model.php.

gform_form_trash_link

gform_form_trash_link

DescriptionUsageParametersExamples1. Change the text of the link2. Prevent a specific Form from being deletedPlacementSinceSource Code

Description

This filter is no longer available since Gravity Forms 2.5.

Allows for modification of the Form Trash Link on the Form Editor page.

Note: Replaced the deprecated gform_form_delete_link filter.

Usage

add_filter( 'gform_form_trash_link', 'your_function_name', 10, 2 );

Parameters

$trash_link stringThe Trash link HTML.$form_id intThe ID of the form being edited.

Examples

1. Change the text of the link

add_filter( 'gform_form_trash_link', 'rename_trash_link', 10, 2 );function rename_trash_link( $trash_link, $form_id ){    $trash_link = str_replace( 'Move to Trash', 'Remove this Form', $trash_link );    return $trash_link;}

2. Prevent a specific Form from being deleted

add_filter( 'gform_form_trash_link', 'prevent_form_deletion', 10, 2 );function prevent_form_deletion( $trash_link, $form_id ){    if ( $form_id == 75 ) {        $trash_link = 'Remove this Form';    }    return $trash_link;}

Placement

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

Since

This filter was added in Gravity Forms version 1.8.Added the $form_id param in version 2.1.2.3.

Source Code

This filter is located in GFFormDetail::forms_page() in form_detail.php.

gform_form_tag

gform_form_tag

DescriptionUsageParametersExamplesSubmit Form to Custom HandlerTurn off autocompletionPlacementSource CodeThird-party ResourcesPlugin: Gravity Forms Tag Editor

Description
This filter is executed when the form is displayed and can be used to completely change the form tag (i.e.

).
Usage
1add_filter( 'gform_form_tag', 'form_tag', 10, 2 );
Parameters

$form_tag string
The string containing the

tag

$form Form Object
The current form.

Examples
Submit Form to Custom Handler
This example changes the action of the form tag, submitting the form to a custom form handler.
123456789add_filter( 'gform_form_tag', 'form_tag', 10, 2 );function form_tag( $form_tag, $form ) {    if ( $form['id'] != 3 ) {        //not the form whose tag you want to change, return the unchanged tag        return $form_tag;    }    $form_tag = preg_replace( "|action='(.*?)'|", "action='custom_handler.php'", $form_tag );    return $form_tag;}
Turn off autocompletion
Turn off autocompletion as described in Mozilla developer docs: How to Turn Off Form Autocompletion
The following will be applied only to a form with id 1.
12345678910add_filter( 'gform_form_tag', 'form_tag', 10, 2 );function form_tag( $form_tag, $form ) {if ( $form['id'] != 1 ) { // change 1 to match your form id//not the form whose tag you want to change, return the unchanged tagreturn $form_tag;}// Turn off autocompletion as described here https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion$form_tag = preg_replace( "|action='|", "autocomplete='off' action='", $form_tag );return $form_tag;}
If you want to apply it to all forms simply remove the if statement.
123456add_filter( 'gform_form_tag', 'form_tag', 10, 2 );function form_tag( $form_tag, $form ) {// Turn off autocompletion as described here https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion$form_tag = preg_replace( "|action='|", "autocomplete='off' action='", $form_tag );return $form_tag;}
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
Third-party Resources
Plugin: Gravity Forms Tag Editor
A simple plugin that makes modifying Gravity Forms tags a breeze. Change any attribute of the form tag with just a few lines of code. Visit the plugin page.

gform_form_switcher_forms

gform_form_switcher_forms

DescriptionParametersExamplesDisplay First Ten FormsPlacementSinceSource Code

Description
Filters through and allows modification of the forms displayed in the Form Switcher dropdown.
Parameters

$forms array
Array containing all forms, sorted by title.

Examples
Display First Ten Forms
add_filter( 'gform_form_switcher_forms', 'limit_form_switcher_forms', 10, 1 );
function limit_form_switcher_forms( $forms ) {
return array_splice( $forms, 0, 10 );
}

Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 2.4.16.
Source Code
This filter is located in GFForms::form_switcher in gravityforms.php

gform_form_summary

gform_form_summary

DescriptionParametersExamplesOrder Forms By Total EntriesPlacementSinceSource Code

Description
Filters through and allows modification of the forms displayed in the Dashboard Forms widget.
Parameters

$forms array
Array containing all forms, including the unread entries count, total entries count and date of last entry submission.

Examples
Order Forms By Total Entries
12345678910add_filter( 'gform_form_summary', 'order_form_summary_by_total_entries', 10, 1 );function order_form_summary_by_total_entries( $forms ) {     usort( $forms, function( $a, $b ) {        return $b['total_entries'] - $a['total_entries'];    } );     return $forms; }
Placement
This code should be placed in the functions.php file of your active theme.
Since
This filter was added in Gravity Forms version 2.4.16.
Source Code
This filter is located in GFFormsModel::get_form_summary in forms_model.php