gform_after_duplicate_form

gform_after_duplicate_form

DescriptionUsageParametersExamplesSource Code

Note: This hook has been deprecated and the hook gform_post_form_duplicated should be used instead.
Description
The 「gform_after_duplicate_form」 action in Gravity Forms is triggered after a form is duplicated, allowing further actions to be performed. The hook provides the ID of the form duplicated and the ID of the new form created.
Usage
add_action( 'gform_after_duplicate_form', 'my_function', 10, 2 );

Parameters

$form_id string
ID of the form being duplicated.

new_id string
ID of the new copy of the form.

Examples
function my_function($form_id, $new_id) {
echo 'Form ' . $form_id . ' was copied into ' . $new_id;
}
add_action( 'gform_after_duplicate_form', 'my_function', 10, 2 );

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

gform_authorizenet_transaction_pre_capture

gform_authorizenet_transaction_pre_capture

DescriptionUsageParametersExamples1. Prevent capture2. Add a custom field3. Set the taxExempt property.4. Set the invoice_num property.5. Add a Description6. Set the shipping address properties7. Set the Customer IP Address as a custom field8. Use Name field for transaction detailsPlacementSource Code

Description

This filter can be used to modify the transaction object before it is sent to Authorize.net. It can also be used to prevent capture by returning false.

Usage

The filter which would run for all 『product and services』 type Authorize.net feeds can be used like so:

add_filter( 'gform_authorizenet_transaction_pre_capture', 'your_function_name', 10, 5 );

Parameters

$transaction object
The Authorize.net transaction object.

$form_data Form Data
An associative array containing the form title, billing address, payment amount, setup fee amount, line items created using the submitted pricing field values and any discounts from coupons.

$config Authorize Net Config
The feed which is currently being processed.

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

$entry Entry Object
The entry which is currently being processed. Since version 2.1.8.

Examples

1. Prevent capture

The following example shows how you can prevent the payment being captured.

add_filter( 'gform_authorizenet_transaction_pre_capture', '__return_false' );

2. Add a custom field

The following example shows how you can add a custom Authorize.net field to the transaction and pass it the value from a form field.

add_filter( 'gform_authorizenet_transaction_pre_capture', 'add_custom_field', 10, 5 );
function add_custom_field( $transaction, $form_data, $config, $form, $entry ) {
if ( $form['id'] == 10 ) {
$value = rgpost( 'input_5');
$transaction->setCustomField( 'your_field_name', $value );
}

return $transaction;
}

3. Set the taxExempt property.

The following example shows how you can add a custom Authorize.net field to the transaction and pass it the value from a form field.

add_filter( 'gform_authorizenet_transaction_pre_capture', 'set_tax_exempt', 10, 5 );
function set_tax_exempt( $transaction, $form_data, $config, $form, $entry ) {
if ( $form['id'] == 10 ) {
$transaction->tax_exempt = 'true';
}

return $transaction;
}

4. Set the invoice_num property.

This example shows how to pass an entry value as the transactions invoice number.

add_filter( 'gform_authorizenet_transaction_pre_capture', function( $transaction, $form_data, $config, $form, $entry ) {
if ( $form['id'] == 10 ) {
$transaction->invoice_num = rgar( $entry, '4' );
}

return $transaction;
}, 10, 5 );

5. Add a Description

This example shows how to add a description (up to 255 characters) for one time transactions in a form with id 30.

add_filter( 'gform_authorizenet_transaction_pre_capture', function( $transaction, $form_data, $config, $form, $entry ) {
if ( $form['id'] != 30 ) { // Update 30 to your form id number
return $transaction;
}

$transaction->description = 'This is my custom description...';

return $transaction;
}, 10, 5 );

6. Set the shipping address properties

This example shows how to pass entry values to the transaction shipping address properties.

add_filter( 'gform_authorizenet_transaction_pre_capture', function( $transaction, $form_data, $config, $form, $entry ) {
if ( $form['id'] == 10 ) {
$transaction->ship_to_first_name = rgar( $entry, '1.3' );
$transaction->ship_to_last_name = rgar( $entry, '1.6' );
$transaction->ship_to_company = rgar( $entry, '2' );
$transaction->ship_to_address = rgar( $entry, '3.1' );
$transaction->ship_to_city = rgar( $entry, '3.3' );
$transaction->ship_to_state = rgar( $entry, '3.4' );
$transaction->ship_to_zip_code = rgar( $entry, '3.5' );
$transaction->ship_to_country = rgar( $entry, '3.6' );
}

return $transaction;
}, 10, 5 );

7. Set the Customer IP Address as a custom field

The current version of the add-on doesn』t support using the customerIP property. This example shows a workaround passing the Customer IP address using a custom field.

add_filter( 'gform_authorizenet_transaction_pre_capture', function( $transaction, $form_data, $config, $form, $entry ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );

$transaction->setCustomField( 'Customer IP', rgar( $entry, 'ip' ) );

GFCommon::log_debug( __METHOD__ . '(): Customer IP set to: ' . rgar( $entry, 'ip' ) );

return $transaction;
}, 10, 5 );

8. Use Name field for transaction details

This example shows how to use a Name field as source for Authorize.net』s transaction details.

add_filter( 'gform_authorizenet_transaction_pre_capture', function ( $transaction, $form_data, $config, $form, $entry ) {
GFCommon::log_debug( __METHOD__ . '(): running.' );

if ( $form['id'] != 1 ) { // Update 1 to your form id number
GFCommon::log_debug( __METHOD__ . '(): Not our desired form, leaving without changes.' );
return $transaction;
}

// Set values for transaction First Name and Last Name from a name field with ID 1.
$transaction->first_name = rgar( $entry, '1.3' );
GFCommon::log_debug( __METHOD__ . '(): First Name: ' . $transaction->first_name );
$transaction->last_name = rgar( $entry, '1.6' );
GFCommon::log_debug( __METHOD__ . '(): Last Name: ' . $transaction->last_name );

return $transaction;
}, 10, 5 );

Placement

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

Source Code

This filter is located in GFAuthorizeNet::authorize() in class-gf-authorizenet.php.

gform_ajax_spinner_url

gform_ajax_spinner_url

DescriptionUsageParametersExamplesChange the spinner image to a custom image file.PlacementSource Code

Description
This filter can be used to change the default AJAX spinner image
Usage
1add_filter( 'gform_ajax_spinner_url', 'custom_spinner_image', 10, 2 );
You can also specify this per form by adding the form id after the hook name.
1add_filter( 'gform_ajax_spinner_url_6', 'custom_spinner_image', 10, 2 );

Parameters

$image_src string
The spinner image URL to be filtered

$form Form Object
Current form.

Examples
Change the spinner image to a custom image file.
1234add_filter( 'gform_ajax_spinner_url', 'spinner_url', 10, 2 );function spinner_url( $image_src, $form ) {    return "http://www.somedomain.com/spinner.png";}
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_after_email

gform_after_email

DescriptionUsageParametersExamples1. Retry sending2. Add note to entryPlacementSource Code

Description
Use this hook to perform actions after a user or admin notification has been sent.
Usage
1add_action( 'gform_after_email', 'after_email', 10, 12 );

Parameters

$is_success bool
Indicates whether the wp_mail function was able to successfully process the mail request without errors.

$to string
Email address to which the message is being sent.

$subject string
Email subject.

$message string
Email body.

$headers array
Email headers.

$attachments array
Email attachment(s).

$message_format string
Email format: text or html.

$from string
From email.

$from_name string
From name.

$bcc string
Bcc email.

$reply_to string
Reply to email.

$entry Entry Object
The entry currently being processed or false if not available.

Examples
1. Retry sending
This example tries to send the email a second time if the original request was unsuccessful.
12345678910add_action( 'gform_after_email', 'after_email', 10, 7 );function after_email( $is_success, $to, $subject, $message, $headers, $attachments, $message_format ) {    if ( ! $is_success ) {        //sending mail failed, try again one more time        $try_again = wp_mail( $to, $subject, $message, $headers, $attachments );        if ( ! $try_again ) {            //still unable to send, do something...perhaps log the failure in a text file        }    }}
2. Add note to entry
This example shows how you can add a note to the entry.
1234add_action( 'gform_after_email', function( $is_success, $to, $subject, $message, $headers, $attachments, $message_format, $from, $from_name, $bcc, $reply_to, $entry ) {    $current_user = wp_get_current_user();    RGFormsModel::add_note( $entry['id'], $current_user->ID, $current_user->display_name, 'the note to be added' );}, 10, 12 );
Placement
This code should be placed in the functions.php file of your active theme.
Source Code
This action hook is located in GFCommon::send_email() in common.php.

gform_authorizenet_validation_message

gform_authorizenet_validation_message

DescriptionUsageParametersExamples1. Use the Authorize.net Response Reason TextPlacementSource Code

Description
This filter can be used to modify the validation message added to the credit card field when Authorize.net returns an error during card authorization.
Usage
The filter which would run for all Authorize.net feeds can be used like so:
1add_filter( 'gform_authorizenet_validation_message', 'your_function_name', 10, 5 );

Parameters

$message string
The default error message.

$validation_result array
An associative array containing the form validation result, the form object, and the number of the page where the validation error occurred.

$post array
The global $_POST containing the input values posted by the browser.

$response object
The response from Authorize.net.

$responsetype string
The type of response. Possible values: arb or aim.

Examples
1. Use the Authorize.net Response Reason Text
12345add_filter( 'gform_authorizenet_validation_message', function( $message, $validation_result, $post, $response, $responsetype ) {    $message = $response->response_reason_text;     return $message;}, 10, 5 );
Placement
Your code snippet should be placed in the functions.php file of your active theme.
Source Code
This filter is located in GFAuthorizeNet::authorize() and GFAuthorizeNet::subscribe() in class-gf-authorizenet.php