Using Gravity Forms ‘gform_authorizenet_validation_message’ PHP filter

The gform_authorizenet_validation_message filter allows you to modify the validation message displayed in the credit card field when Authorize.net returns an error during card authorization.

Usage

To use this filter, add the following line to your functions.php file:

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

Parameters

  • $message (string): The default error message.
  • $validation_result (array): Contains the form validation result, 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’.

More information

See Gravity Forms Docs: gform_authorizenet_validation_message

Examples

Custom validation message

Modify the default validation message when an error occurs during card authorization.

function change_validation_message($message, $validation_result, $post, $response, $responsetype) {
    // your custom code here
    $message = "Your custom validation message.";
    return $message;
}
add_filter('gform_authorizenet_validation_message', 'change_validation_message', 10, 5);

Show response reason text

Display the Authorize.net response reason text as the validation message.

function show_response_reason_text($message, $validation_result, $post, $response, $responsetype) {
    $message = $response->response_reason_text;
    return $message;
}
add_filter('gform_authorizenet_validation_message', 'show_response_reason_text', 10, 5);

Change message based on response code

Modify the validation message based on the response code returned by Authorize.net.

function custom_message_based_on_response_code($message, $validation_result, $post, $response, $responsetype) {
    if ($response->response_code == 2) {
        $message = "Declined: Please check your card details.";
    } elseif ($response->response_code == 3) {
        $message = "Error: Please contact support.";
    }
    return $message;
}
add_filter('gform_authorizenet_validation_message', 'custom_message_based_on_response_code', 10, 5);

Log error messages

Log the validation message to a file when an error occurs during card authorization.

function log_validation_message($message, $validation_result, $post, $response, $responsetype) {
    error_log("Authorize.net error: " . $message);
    return $message;
}
add_filter('gform_authorizenet_validation_message', 'log_validation_message', 10, 5);

Change message for specific form

Change the validation message for a specific form by checking the form ID.

function custom_message_for_specific_form($message, $validation_result, $post, $response, $responsetype) {
    $form = $validation_result['form'];
    if ($form['id'] == 123) {
        $message = "Custom message for form ID 123.";
    }
    return $message;
}
add_filter('gform_authorizenet_validation_message', 'custom_message_for_specific_form', 10, 5);