• I’m trying to require first and last name fields on the frontend profile update page. The code shown below successfully displays error messages but allows updates to the custom fields. Expected behavior is if any error is generated, none of the form fields should update.

    Examples of problem:

    1) First name entered, last name left blank. Update profile. ‘Last name’ error generated. So far, so good.

    2) First name removed from field, last name left blank. Update profile. ‘First name’ and ‘last name’ errors generated, but ‘First name’ updated to ‘blank’ instead of keeping the original value.

    3) First name left blank, last name entered. Update profile. ‘First name’ error generated, but ‘last name’ is updated to the entered value.

    Code in functions.php:

    add_action( 'user_profile_update_errors', 'require_first_last_name' );
    
    function require_first_last_name( $errors ) {
    
    	if (empty($_POST['first_name'])) {
    		$errors->add('empty_first_name', '<strong>ERROR</strong>: Please enter your first name.');
    	}
    	if (empty($_POST['last_name'])) {
    		$errors->add('empty_last_name', '<strong>ERROR</strong>: Please enter your last name.');
    }
    return $errors;

    Note: I have looked for but not found a solution to this problem. I did find a similar topic where the author said “TML 6.3 (coming soon) will have better handling of such scenarios.” I am using 6.3.10 and have not found the answer.

    https://www.ads-software.com/plugins/theme-my-login/

  • The topic ‘Requiring custom fields on frontend profile form’ is closed to new replies.