How to Change Validation Messages for User Registration Addon

Overview

Would you like to change the validation messages for your WPForms User Registration Addon? You can display further validation messages such as User Name Already Exists or Email Already Exists messages to your visitors when they complete your registration form. This tutorial will show you how to use PHP to create these additional validation messages.

After installing the User Registration addon for WPForms, two new templates will become available: User Login Form and User Registration Form.

In addition to using standard validation messages, both of these forms will display content-specific errors when needed.

Implementation Options

Below, we’ll cover each of these validation messages. You can add any of the code snippets to your site and adjust their content to fit your needs.

Username already exists error

By default, this error will display: “A user with that username already exists.” In the code example below, we modify this text and add a link to let the user reset their password (in case they registered earlier with this username and forgot).

/**
 * Change the User Registration Form error message for already existing email address.
 * 
 * @link https://wpforms.com/developers/change-validation-messages-for-user-registration-addon/
 *
 */
function wpf_dev_user_registration_username_exists( $msg ) {
	$msg = 'A user with that username already exists. Need to <a href="';
	$msg .= esc_url( wp_lostpassword_url() );
	$msg .= '"> reset your password?</a>';
	return $msg;
}
add_filter( 'wpforms_user_registration_username_exists', 'wpf_dev_user_registration_username_exists' );

Email already exists error

By default, this error will display: “A user with that email already exists.” In the code example below, we modify this text and add a link to let the user reset their password (in case they registered earlier with this email address and forgot).

/**
 * Change the User Registration Form error message for already existing username.
 * 
 * @link https://wpforms.com/developers/change-validation-messages-for-user-registration-addon/
 *
 */
function wpf_dev_user_registration_email_exists( $msg ) {
	$msg = 'A user with that email already exists. Need to <a href="';
	$msg .= esc_url( wp_lostpassword_url() );
	$msg .= '"> reset your password?</a>';
	return $msg;
}
add_filter( 'wpforms_user_registration_email_exists', 'wpf_dev_user_registration_email_exists' );

Login form error

By default, the login form will display hints much like the traditional WordPress login form. By using the code snippet below, you can create a more generic message without a hint.

/**
 * Change the User Login Form error message.
 * 
 * @link https://wpforms.com/developers/change-validation-messages-for-user-registration-addon/
 *
 */
function wpf_dev_user_registration_login_error() {
	$msg = 'Sorry something went wrong! <a href="';
	$msg .= esc_url( wp_lostpassword_url() );
	$msg .= '">Reset your password?</a>';
	return $msg;
}
add_filter( 'wpforms_user_registration_login_error', 'wpf_dev_user_registration_login_error', 10, 2 );

And that’s all you need to add additional validation messages for the User Registration addon. Would you like to automatically log in your users after they’ve completed registration? Please review our tutorial on How to Automatically Log in Users After Registration.