Using Gravity Forms ‘gform_is_valid_notification_to’ PHP filter

The gform_is_valid_notification_to filter enables you to change the email validation for the TO address on notification pages. This can be useful to allow merge tags or shortcodes to be added to the TO field.

Usage

add_filter('gform_is_valid_notification_to', 'validate_to_email', 10, 4);

Parameters

  • $is_valid (boolean): The value being filtered. True if the to email is valid, false otherwise. Gravity Forms performs the validation before executing this hook, so $is_valid will contain the result of that validation. To override Gravity Form’s validation, simply set the value of this variable to true or false and return it.
  • $to_type (string): The type of “Send To” that is configured. The possible values are “email”, “field”, and “routing”.
  • $to_email (string): The email address configured. Only applies when type ($to_type) is set to “email”.
  • $to_field (string): The ID of the field selected to be used as the “Send To”. Only applies when type ($to_type) is set to “field”.

More information

See Gravity Forms Docs: gform_is_valid_notification_to

Examples

Allow {user:user_email} merge tag for notifications “Send To” email

This example demonstrates how to allow the merge tag {user:user_email} to be used for notifications “Send To” email.

add_filter('gform_is_valid_notification_to', 'validate_to_email', 10, 4);
function validate_to_email($is_valid, $to_type, $to_email, $to_field) {
    if ($to_email == '{user:user_email}') {
        return true;
    }
    return $is_valid;
}

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

Source Code: This filter is located in GFNotification::is_valid_notification_to() in notification.php.