Support » Plugin: Ultimate Member – User Profile, User Registration, Login & Membership Plugin » issue when using mobile field as username

  • Dear
    we add the next code to let us can be able to use mobile field instead username in some registration form and it is work and at the same time I need another registration form that is normal (use username)
    but when use the normal form
    the username of the created user become empty in user edit profile page in backend

    I need to use tow registration form

    form uses mobile field as username after using the next code it works right and the created username is phone number (right)

    add_action("um_submit_form_register","um_090321_mobile_number_zero_validation", 1 );
    function um_090321_mobile_number_zero_validation( $post_form ){
     
        if(  isset( $post_form['mobile_number'] ) && ! empty( $post_form['mobile_number'] ) ){
            if ( strpos( $post_form['mobile_number'], '0') !== 0) {
                UM()->form()->add_error('mobile_number', __( 'Mobile Number must begin with 0', 'ultimate-member' ) );
            }
            if( username_exists( $post_form['mobile_number'] ) )  {
                UM()->form()->add_error('mobile_number', __( 'Mobile Number already registered', 'ultimate-member' ) );
            }        
        }
    }
    
    add_action("um_user_register","um_090321_after_register_complete", -1, 2 );
    function um_090321_after_register_complete( $user_id, $args ){
       
        global $wpdb;
    
        $wpdb->update( $wpdb->users, array('user_login' => $args['mobile_number'] ), array('ID' => $user_id));
    
    }

    but
    when using normal form that use username field to create username I got the next issue
    the username field of the created user is empty without any username inside it

    so please how to fix this issue
    regards

Viewing 15 replies - 1 through 15 (of 28 total)
  • @makmerghen

    Why do you want to have Mobile Number as username?

    If you want users also to login with their mobile number, you can use this code snippet:

    https://github.com/MissVeronica/UM-Mobile-Number-Login

    Thread Starter makmerghen

    (@makmerghen)

    @missveronicatv I want each user to use only one unique mobile number thats why

    so if I use this code users can use their mobile number to log in even if they register with another username or what ?

    and another question can I make the mobile number field unique ? and how

    best regards

    @makmerghen

    so if I use this code users can use their mobile number to log in even if they register with another username or what ?

    Yes, user can login with username, email or mobile number.
    You decide which one of these or all to use by design of your login page.

    can I make the mobile number field unique ? and how

    Yes the code snippet has a custom validation for unique mobile number.

    Thread Starter makmerghen

    (@makmerghen)

    @missveronicatv
    so I have to add the three fields(username, email, mobiel number) in the registration field right ?
    and such as username and email is unique the code you provide will make the mobile number unique too, right?

    @makmerghen

    Two options for the use of Mobile Number Login are available:

    1. The UM Forms Designer “Username or email” Login field also accepts a Mobile Number for identification of the User.

    2. The UM Login Form can have a Mobile Number Form text field as the only identification of the User for Login.

    Thread Starter makmerghen

    (@makmerghen)

    @missveronicatv I understood the second point login form can contain only one field username or email or mobile number in addition to the password field

    regarding the registration form please confirm in case i want user to use username or email or mobile field to log in so at this case i must add three fields of username and email and mobile number field in the registration form using registration form designer right?

    @makmerghen

    I understood the second point login form can contain only one field username or email or mobile number in addition to the password field

    You can use your current Login form if it’s an Username/Email login field and this field will also accept a mobile number with this code snippet. This alternative is required if you may have duplicate numbers from old registrations, so the user can switch and login with username or email address.

    regarding the registration form please confirm in case i want user to use username or email or mobile field to log in so at this case i must add three fields of username and email and mobile number field in the registration form using registration form designer right?

    Yes, if you have these three fields today you can use the current Registration form.

    If you today have mobile numbers registered and there are duplicates those duplicate mobile numbers can’t be used for login.
    Error message: “There are more than one user registered with this mobile number”

    Thread Starter makmerghen

    (@makmerghen)

    @missveronicatv thanks a lot for the clarification
    wish you all the best

    Thread Starter makmerghen

    (@makmerghen)

    @missveronicatv I did test to create registration form with the next possibilities

    1- field of email and mobile with email with filling all
    result created username = email

    2- field of mobile and email and first name and last name with filling all except email empty
    result created username = firstname+lastname (if this combination is existed its the create username got additional number to be unique)

    3- field of mobile only filled and remove first and last name and email is empty
    result created username = random username in stead of creating username = mobile number

    4- field of mobile only filled with mobile number I already used for another user before
    result = it created the new user without telling that the phone number is already exist

    5- field of username and email and mobile with filling all
    result = created username = username field but I can only login using username , it refuse using email or mobile number and say Password is incorrect. Please try again. although it is right

    so please advise for number 3and 4 and 5
    regards

    @makmerghen

    Number 3:

    Add this code snippet:

    add_filter( 'um_add_user_frontend_submitted', 'um_add_user_frontend_submitted_empty_username', 10, 1 );
    
    function um_add_user_frontend_submitted_empty_username( $args ) {
    
        if( empty( $args['user_login'] ) && !empty( $args['mobile_number'] )) {
            $args['user_login'] = $args['mobile_number'];
            $args['submitted']['user_login'] = $args['mobile_number'];
        }
        return $args;
    }

    Number 4:

    There must be a normalization of the registered mobile numbers.
    Currently you can register mobile numbers both with spaces/dots and without spaces/dots and they are not equal even if all the digits are the same.

    There is a feature in HTML5 to validate and normalize mobile numbers and also JavaScript libraries to validate/normalize mobile numbers per country standards.

    Number 5:

    Login with username, email or mobile_number only if your identification in the login form is using the username metakey.

    Thread Starter makmerghen

    (@makmerghen)

    @missveronicatv
    Number 3 thank you the code fix the issue
    number 5 thank you I chaned login field to be username and email and it worked

    number 4 still the issue even when I used exactly the same number without any additional spaces or dots
    what if I changed the Validate of the field to be in stead phone number to be unique username or unique metakey
    does it can fix the issue ? or what do you recommenced ?

    best regards

    • This reply was modified 8 months, 1 week ago by makmerghen.

    @makmerghen

    what if I changed the Validate of the field to be in stead phone number

    From the readme.md file:

    Set the “mobile_number” meta key value Validation to “Custom Validation” and add the Validation as unique_mobile_number.

    The code snippet is first using UM()->validation()->is_phone_number
    then doing a database lookup for the mobile number to be unique.

    Thread Starter makmerghen

    (@makmerghen)

    @missveronicatv thank you now everything work well oncechanging validation of mobile phone field as you explain the message of appear and didn’t continue the registration till changing the phone number

    thank you a lot for your helping
    best regards

    @makmerghen

    A follow up on your number 4 issue:

    You can try this code snippet which will make the mobile number field on your registration page the HTML type="tel" instead of type="text" and you can use other plugins for mobile number country codes based on geolocation.

    In addition you also get with this code snippet the mobile number keayboard instead of alfabetic on mobiles during registration.

    add_filter( "um_mobile_number_form_edit_field", "um_mobile_number_form_edit_field_tel", 10, 2 );
    add_filter( "um_phone_number_form_edit_field", "um_mobile_number_form_edit_field_tel", 10, 2 );
        
        function um_mobile_number_form_edit_field_tel( $output, $set_mode ) {
    
            if( $set_mode == 'register' ) {
                $output = str_replace( 'type="text"', 'type="tel"', $output );
            }
            return $output;
        }

    Example of geolocation/mobile country code and country flag plugin:

    https://wordpress.org/plugins/international-telephone-input-with-flags-and-dial-codes/

    and a Mobile Phone Validator Plugin:

    https://wordpress.org/plugins/byteplant-phone-validator/

    Thread Starter makmerghen

    (@makmerghen)

    @missveronicatv thanks a lot I am so happy to know someone as helpful as you
    I really thank you and wish you all the best

Viewing 15 replies - 1 through 15 (of 28 total)
  • The topic ‘issue when using mobile field as username’ is closed to new replies.