• Resolved connorhsm

    (@connorhsm)


    Am I required to purchase the custom fields add on just to add a repeat password field to the registration form?
    Similar to the reset password form.

    Or is there another way to achieve this?

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Alessandro Tesoro

    (@alessandrotesoro)

    Hi @connorhsm

    You do not need to purchase the addon for that specific feature. Furthermore the addon doesn’t even provide it.

    You can add the following code to your theme’s functions.php file and a confirm password field will appear into your registration form.

    
    function wpum_my_psw_field_confirmation( $fields ) {
    
    	$fields[ 'confirm_psw' ] = array(
    		'label'       => 'Confirm password',
    		'type'        => 'password',
    		'meta'        => false,
    		'required'    => true,
    		'description' => 'Add something here if needed',
    		'priority' => 30
    	);
    
    	return $fields;
    
    }
    add_filter( 'wpum_get_registration_fields', 'wpum_my_psw_field_confirmation' );
    
    function wpum_verify_my_psw_confirmation( $pass, $fields, $values, $form ) {
    
    	if ( $form === 'registration' && isset( $values['register']['confirm_psw'] ) ) {
    
    		$psw1 = $values['register']['user_password'];
    		$psw2 = $values['register']['confirm_psw'];
    
    		if ( $psw1 !== $psw2 ) {
    			return new WP_Error( 'psw-validation-error', 'Passwords do not match.' );
    		}
    
    	}
    
    	return $pass;
    
    }
    add_filter( 'submit_wpum_form_validate_fields', 'wpum_verify_my_psw_confirmation', 10, 4 );
    
    Thread Starter connorhsm

    (@connorhsm)

    This worked a treat, thanks @alessandrotesoro !

    Is it possible to do the same for a secondary email confirmation field?

    And also, can something about this topic be added to the documentation if it does not already exist?

    Thanks again.

    Plugin Contributor Alessandro Tesoro

    (@alessandrotesoro)

    Hi @connorhsm

    Yes that’s correct, you can also add a secondary email field to make the user confirm the email. Here’s the code, it’s basically the same with just the name of the fields changed.

    function wpum_my_email_field_confirmation( $fields ) {
    
    	$fields[ 'confirm_email' ] = array(
    		'label'       => 'Confirm email',
    		'type'        => 'email',
    		'meta'        => false,
    		'required'    => true,
    		'description' => 'Add something here if needed',
    		'priority' => 0
    	);
    
    	return $fields;
    
    }
    add_filter( 'wpum_get_registration_fields', 'wpum_my_email_field_confirmation' );
    
    function wpum_verify_my_email_confirmation( $pass, $fields, $values, $form ) {
    
    	if ( $form === 'registration' && isset( $values['register']['user_email'] ) ) {
    
    		$email1 = $values['register']['user_email'];
    		$email2 = $values['register']['confirm_email'];
    
    		if ( $email1 !== $email2 ) {
    			return new WP_Error( 'psw-validation-error', 'Emails do not match.' );
    		}
    
    	}
    
    	return $pass;
    
    }
    add_filter( 'submit_wpum_form_validate_fields', 'wpum_verify_my_email_confirmation', 10, 4 );

    I’ll add some more info the documentation soon.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Repeat password on user registration’ is closed to new replies.