We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38783
    • 571 Posts
    Hello,

    I am using the Login extra to allow users to request a user account on a website.

    This is working well but I would like to ensure that the username input by the user is not already in use.
    The same should probably be true of the email field.

    (I am using Bob Rays ClassExtender to provide additional user fields which are included in the registration form. These are also working correctly.)

    I see that this question did crop up once before in the forums but no answer seems to have been offered. https://forums.modx.com/thread/80908/login----registration----validation----existing. This was a few years ago and I am hoping there might be an answer now.

    I have tried registering as a new user using an existing user name and the form silently fails.

    Any help would be greatly appreciated.

    The code I have at the moment is as follows:
    <h2>Register</h2> 
    
    [[!Register? 
        &submitVar=`loginRegisterBtn` 
        &activationResourceId=`34` 
        &activationEmailTpl=`lgnActivateEmailTpl` 
        &activationEmailSubject=`Thanks for Registering!` 
        &submittedResourceId=`33` 
        &usergroups=`registrants` 
        &validate=`no spam:blank,
        username:required:minLength=^6^,
        password:required:minLength=^8^,
        password_confirm:password_confirm=^password^`
        &useExtended=`0` 
        &postHooks=`ExtUserRegisterPosthook` 
        &placeholderPrefix=`reg.`]] 
       
    <div class="register"> 
        <div class="registerMessage">[[+error.message]]</div> 
           
        <form class="form" action="[[~[[*id]]]]" method="post"> 
            <input type="hidden" name="nospam:blank" value="" /> 
               
             <label for="username">[[%register.username? &namespace=`login` &topic=`register`]] 
                <span class="error">[[!+reg.error.username]]</span> 
            </label> 
            <input type="text" name="username" id="username" value="[[+username]]" /> 
              
            <label for="password">[[%register.password]] 
                <span class="error">[[!+reg.error.password]]</span> 
            </label> 
            <input type="password" name="password" id="password" value="[[+password]]" /> 
               
            <label for="password_confirm">[[%register.password_confirm]] 
                <span class="error">[[!+reg.error.password_confirm]]</span> 
            </label> 
            <input type="password" name="password_confirm" id="password_confirm" value="[[+password_confirm]]" /> 
               
            <label for="email">[[%register.email]] 
                <span class="error">[[!+reg.error.email]]</span> 
            </label> 
            <input type="text" name="email:email" id="email" value="[[+email]]" /> 
    
            <label for="firstName">First Name</label> 
                <input type="text" name="firstName" value="[[!+reg.firstName]]" /> 
            <span class="validateError">[[!+reg.error.firstName]]</span> 
      
            <label for="lastName">Last Name</label> 
                <input type="text" name="lastName" value="[[!+reg.lastName]]" /> 
            <span class="validateError">[[!+reg.error.lastName]]</span> 
    
            <label for="primaryPhoneNumber">Primary Phone Number</label> 
                <input type="text" name="primaryPhoneNumber" value="[[!+reg.primaryPhoneNumber]]" /> 
            <span class="validateError">[[!+reg.error.primaryPhoneNumber]]</span> 
    
    
    
            <br class="clear" /> 
               
            <div class="form-buttons"> 
                <input type="submit" name="loginRegisterBtn" value="Register" /> 
            </div> 
        </form> 
    </div>
    

    This question has been answered by andytough. See the first response.

    [ed. note: andytough last edited this post 7 years, 10 months ago.]
      If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

      email: [email protected] | website: https://andytough.com
      • 3749
      • 24,544 Posts
      Register may already be checking for duplicate usernames.

      I think your error placeholder needs to be:

      <span class="error">[[!+error.reg.username]]</span>


      with a similar change to the other error placeholders.
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • discuss.answer
        • 38783
        • 571 Posts
        Hello Bob,

        Thanks for your help and apologies for not replying sooner. I actually stumbled across the solution here:
        https://forums.modx.com/thread/81750/using-same-username-overwrites-an-existing-user

        I had not put in an instruction to validate whether or not the user existed.

        login.register was checking but did not return an error when a user name was found to exist.

        So adding username:checkExists to my validiation has worked. The validation code now reads:

        &validate=`nospam:blank, username:required, username:checkExists, password:required:minLength=^8^, password_confirm:password_confirm=^password^


        Of course in the meantime a requirement has arisen to automatically generate an alphanumeric username when people request registration! So I expect I will be back here on the forums soon after I have failed to get that working!

        Thanks again.

        Andy
          If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

          email: [email protected] | website: https://andytough.com