Description
The gform_is_valid_notification_to filter allows you to change the email validation for the TO address on notification pages. This allows merge tags or shortcodes to be added to the TO field.
Usage
The following would apply to all forms.
add_filter( 'gform_is_valid_notification_to', 'your_function_name', 10, 4 );
| Parameter | Type | Description |
|---|---|---|
| $is_valid | boolean | The value being filtered. True if the TO email is valid, false otherwise. Gravity Forms performs validation before executing this hook, so $is_valid will contain the result of that validation. To override it, set this value to true or false and return it. |
| $to_type | string | The type of Send To that is configured. Possible values are email, field, and routing. |
| $to_email | string | The email address configured. Only applies when $to_type is set to email. |
| $to_field | string | The ID of the field selected as the Send To. Only applies when $to_type is set to field. |
Examples
Allow a Merge Tag in the Notification TO Field
The following example demonstrates how to allow the merge tag {user:user_email} to be used for the notification 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 can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Source Code
This filter is located in GFNotification::is_valid_notification_to() in notification.php