The gform_user_registration_validation_message filter allows you to customize the default validation message for user registration in Gravity Forms.
Usage
add_filter('gform_user_registration_validation_message', 'your_function_name', 10, 2);
Parameters
- $message (string) – The validation message for the current validation error.
- $form (Form Object) – The form currently being processed.
More information
See Gravity Forms Docs: gform_user_registration_validation_message
Examples
Change the default “username already registered” message
This example updates the validation message when the submitted username is already registered.
add_filter('gform_user_registration_validation_message', 'update_validation_msgs', 10, 2); function update_validation_msgs($message, $form) { if ($message == 'This username is already registered') { $message = "We're sorry, this username is already registered. Try submitting with a different username."; } return $message; }
Add a prefix to all validation messages
This example adds a prefix to all validation messages.
add_filter('gform_user_registration_validation_message', 'add_prefix_to_validation_msgs', 10, 2); function add_prefix_to_validation_msgs($message, $form) { $prefix = 'Oops! '; return $prefix . $message; }
Change the validation message based on form ID
This example customizes the validation message for a specific form ID.
add_filter('gform_user_registration_validation_message', 'change_message_for_form', 10, 2); function change_message_for_form($message, $form) { if ($form['id'] == 1) { $message = 'Please fix the following errors:'; } return $message; }
Change the validation message based on form title
This example changes the validation message based on the form title.
add_filter('gform_user_registration_validation_message', 'change_message_for_form_title', 10, 2); function change_message_for_form_title($message, $form) { if ($form['title'] == 'Registration') { $message = 'Please correct the following registration errors:'; } return $message; }
Display a custom validation message for a specific field
This example shows how to display a custom validation message for a specific field based on its ID.
add_filter('gform_user_registration_validation_message', 'custom_validation_message_for_field', 10, 2); function custom_validation_message_for_field($message, $form) { foreach ($form['fields'] as $field) { if ($field['id'] == 5 && !RGFormsModel::is_field_value_acceptable($field, rgpost("input_{$field['id']}"))) { $message = 'Please enter a valid value for this field.'; break; } } return $message; }