PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Upon update 1.5 you cannot use the email field to populate the username field!

  1. Hello,

    I have been using the User Registration add-on from some time, since 1.2 I think.

    I have always been updating it on my project and since now I have had no problems. As it is so good.

    However my Wordpress network multisite install uses the email address form field to populate both the username and email fields in the User Registration Add-On.

    Since updating to 1.5 I now cannot validate forms because my email form field is prompted by this message: Only lowercase letters (a-z) and numbers are allowed.

    I cannot revert to using non-email usernames as my client wishes it to be this way.

    I checked your changelog.txt file to see if you purposely done this and I cannot see any notes of this change, and am now stuck what to do. Can't seem to find anyone online with the same problem.

    I have reverted back to 1.4 but after checking out your changelog in 1.5, I would really like to be using 1.5.

    Can you help?

    Many thanks

    Posted 11 years ago on Monday April 8, 2013 | Permalink
  2. The username restrictions come from WordPress: we just enforce them. According to WordPress, the username can only contain alphanumeric characters (A-Z, 0-9), underscores and dashes. (spaces are also allowed but that is not mentioned.)

    How were you allowing the email address to be used as a username previously? Was that from a plugin?

    Posted 11 years ago on Tuesday April 9, 2013 | Permalink
  3. Hi Chris.

    Thats does make sense. However I am just using the User registration add-on 1.4. No other plugins.

    With these settings... http://i.imgur.com/UcuEIWq.png

    I have been using this method on my clients project for the last two years, and have never been prompted with the standard wordpress enforcement: Only lowercase letters (a-z) and numbers are allowed.

    Only upon updating to User registration add-on 1.5, I am now getting issues with validation.

    Have you got a filter or some way of by passing this validation in 1.5? I am now having to use 1.4 again just to get by

    Many Thanks

    Posted 11 years ago on Tuesday April 9, 2013 | Permalink
  4. I'll ask the development team about this one for you. I believe there is a way to bypass that username validation but I can't recall the method right now.

    Posted 11 years ago on Tuesday April 9, 2013 | Permalink
  5. You are correct about changes in 1.5. There were changes made with this version to use the WordPress validation, which explains why you can no longer use the email address as the username. To get around this, you can use the gform_user_registration_validation hook http://www.gravityhelp.com/documentation/page/Gform_user_registration_validation and do your own validation on the field and/or update the existing validation of the field in the form object to be successful.

    Posted 11 years ago on Tuesday April 9, 2013 | Permalink
  6. Josh, did you get this working? I also liked that feature. I am not sure how to implement the workaround.

    Posted 11 years ago on Monday April 22, 2013 | Permalink
  7. I also have been facing this issue. I was able to implement the workaround with the following:

    add_filter( 'gform_user_registration_validation', 'custom_filter_registration', 10, 3 );
    function custom_filter_registration( $form, $config, $pagenum ) {
    foreach( $form['fields'] as $k => $field ) {
    if( $field['label'] == 'Email' ) {
    $field['failed_validation'] = false;
    $field['validation_message'] = '';
    $form['fields'][ $k ] = $field;
    }

    return $form;
    }

    This is simple and naive, but it works and the validation can be extended later. The issue is now, however, that the First Name and Last Name fields are not being saved in the user account (they are being saved in the form entry, however). Can anyone shed any light as to why this is?

    Posted 11 years ago on Friday May 10, 2013 | Permalink
  8. benhamil
    Member

    I have modified ABT's code above, and made a few improvements:

    1. It looks for the email field by GF type, instead of label.
    2. When it finds the type, it verifies that it is a proper email address.
    3. It verifies that the email matches the confirmation value.
    4. It verifies that the "username" (re: email) is not already registered.

    It seems that my validation message for #4 isn't being displayed (GF is overriding it with "Username is already registered"), but it serves my purpose, so I haven't investigated why.

    The setup of my form in GF is as follows:

    • no username field
    • email address field with confirmation enabled
    • user registration: create user maps both username + email address to the email form field

    I hope anyone who stumbles upon this finds it useful. I imagine that a LOT of people are trying to do this. GF should really add a solution to the documentation!

    // allow user to register with email address by stripping validation errors on
    // the email address, so we need to verify that it meets the following conditions:
    // 1. Proper email address
    // 2. Email address matches confirmation value
    // 3. Email address is not already registered
    add_filter( 'gform_user_registration_validation', 'custom_filter_registration', 10, 3 );
    function custom_filter_registration( $form, $config, $pagenum )
    {
    	foreach( $form['fields'] as $k => $field )
    	{
    		if( strtolower($field['type']) == 'email' )
    		{
    			// get email address + confirmation value
    			$id = $field['id'];
    			$email_1 = strtolower($_POST['input_' . $id]);
    			$email_2 = strtolower($_POST['input_' . $id . '_2']);
    			// verify: proper email, and email matches confirmation
    			if( is_valid_email($email_1) && $email_1 == $email_2 )
    			{
    				// verify: email is not already used
    				if( !function_exists('username_exists') )
    					require_once(ABSPATH . WPINC . "/registration.php");
    				if( username_exists($email_1) )
    				{
    					$field['failed_validation'] = true;
    					$field['validation_message'] = 'The email ' . $email_1 . ' is already registered.';
    				} else {
    					// OK: remove validation errors
    					$field['failed_validation'] = false;
    					$field['validation_message'] = '';
    					$form['fields'][ $k ] = $field;
    				}
    			}
    		}
    	}
    	return $form;
    }
    
    function is_valid_email($email) {
    	return preg_match("/^[_a-z0-9-]+(\.[_a-z0-9+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$/i", $email);
    }
    Posted 10 years ago on Wednesday July 3, 2013 | Permalink
  9. Awesome! Thanks, that worked nicely.

    Posted 10 years ago on Sunday July 7, 2013 | Permalink

This topic has been resolved and has been closed to new replies.