We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46886
    • 1,154 Posts
    Hello all, I want to require my new users to provide their birthdate when registering. I don't care if the data is kept in the proper column of the database, so I am using extended fields instead of messing with the native age function inside modx. This will allow me to calculate average age and see different age groups clearly.

    But I need to require a date format and validate it, and maybe need to provide a selection box. I can imagine what the code might look like, but haven't had success to find anything useful.

    Could someone provide a kind pointer in the right direction? Would save me a lot of time.

    Thanks in advance!

    EDIT: Just to be clear the birthdate and age calculation in modx doesn't work very well, and I don't need to open a can of worms. I won't show age of users to others, so its not about calculating age at all. I just want to use a custom field to gather this info for later use.

    Here is my register snippet and form now, it works fine and validates if something is in the birthdate box, but doesn't enforce a format yet:

    <legend class="loginFPLegend">Register</legend>
    [[!Register?
        &submitVar=`registerbtn`
        &activationResourceId=`9`
        &activationEmailTpl=`myActivationEmailTpl`
        &activationEmailSubject=`Thanks for Registering!`
        &submittedResourceId=`13`
        &usergroups=`19`
        &validate=`nospam:blank,
      username:required:minLength=^6^,
      password:required:minLength=^6^,
      password_confirm:password_confirm=^password^,
      fullname:required,
      [b]birthdate:required,[/b]
      email:required:email`
        &placeholderPrefix=`reg.`
    ]]
     
    
    <div class="register">
        <div class="registerMessage">[[!+reg.error.message]]</div>
        <form class="form" action="[[~[[*id]]]]" method="post">
            <input type="hidden" name="nospam" value="[[!+reg.nospam]]" />
     
            <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="[[!+reg.username]]" />
    
            <label for="fullname">[[%register.fullname]]
                <span class="error">[[!+reg.error.fullname]]</span>
            </label>
            <input type="text" name="fullname" id="fullname" value="[[!+reg.fullname]]" />
     
            <label for="password">[[%register.password]]
                <span class="error">[[!+reg.error.password]]</span>
            </label>
            <input type="password" name="password" id="password" value="[[!+reg.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="[[!+reg.password_confirm]]" />
    
    
    [b]        <label for="birthdate">Birthdate
                <span class="error">[[!+reg.error.birthdate]]</span>
            </label>
            <input type="text" name="birthdate" id="birthdate" value="[[!+reg.birthdate]]" />[/b]
     
            <label for="email">[[%register.email]]
                <span class="error">[[!+reg.error.email]]</span>
            </label>
            <input type="text" name="email" id="email" value="[[!+reg.email]]" />
     
            <div class="form-buttons">
                <input type="submit" name="registerbtn" value="Register" />
            </div>
        </form>

    This question has been answered by nir-z. See the first response.

    [ed. note: nuan88 last edited this post 12 years, 3 months ago.]
    • discuss.answer
      • 36996
      • 211 Posts
        • 46886
        • 1,154 Posts
        Hmm looks good, but how shall I combine the register and formit calls? Would the formit call go inside the register form, or do I even need the formit call at all?

        Maybe...just add a value in my current call like this:

        ...
        birthdate:required,
        birthdate:isDate=^%Y-%m-%d^,
        ...

        Will have to try it out...
          • 36996
          • 211 Posts
          Just add the validator to your register call I think
            • 46886
            • 1,154 Posts
            Thanks Nir its really helpful to me. Cheers!