We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9995
    • 1,613 Posts
    How do i add the gender and date of birth fields when someone wants to register?

    Really nead some help on this one!


    [ed. note: fourroses666 last edited this post 14 years, 6 months ago.]
      Evolution user, I like the back-end speed and simplicity smiley
      • 30912
      • 463 Posts
      You need to use the extended fields - http://rtfm.modx.com/display/ADDON/Login.Using+Custom+Fields

      I used similar for a newsletter:

        
              <label for="newsletter">Newsletter* </label>
              <select name="newsletter:required" id="newsletter">
                <option>[[+newsletter]]</option>
                <option value="Yes" selected>Yes</option>
                <option value="No">No</option>
              </select>
              <span class="error">[[+error.newsletter]]</span> 


      As for date, I'm not sure, you could do it with drop downs and have one for each field, or try and use a datepicker. (that i cant help with)

      HTH

      EDIT: Register Automatically checks for fields that are not in the database and adds them as an extedned field there si no switch to turn it on.

      Just ensure you use a submitVar [ed. note: Tyreal2012 last edited this post 14 years, 6 months ago.]
        • 9995
        • 1,613 Posts
        Thanks, i got it working as custom field.

        To bad i don't know how to use the excisting gender field.
        Anyone who got this working?
          Evolution user, I like the back-end speed and simplicity smiley
          • 30912
          • 463 Posts
          didnt realise there was a gender field already, theorteically it should work the same way, but use the gender field name from the database.

          so instead of [[+newsletter]] should just be [[+gender]] i think.
            • 16348
            • 64 Posts
            Both gender and dob are standard fields in the user profile. For the gender field I'm using standard radio buttons. The dob field is a bit trickier due to the way that modx stores the actual date in the database.
            In this post you will find my solution for the dob field. https://forums.modx.com/thread/44846/date-of-birth-amp-updateprofile?page=2#dis-post-257977
              • 3749
              • 24,544 Posts
              Gender is a one-digit integer field. Here's how the Manager interprets it:

              Unset: 0
              Male: 1
              Female: 2


              ---------------------------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
              MODX info for everyone: http://bobsguides.com/modx.html
                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
                • 9995
                • 1,613 Posts
                Thanks guys,

                Bit late call, gender is fixed, for others:

                <label for="gender">Gender </label>
                <select name="gender:required" id="gender">
                  <option>[[+gender]]</option>
                  <option value="1">Male</option>
                  <option value="2">Female</option>
                </select>
                <span class="error">[[+error.gender]]</span>
                




                  Evolution user, I like the back-end speed and simplicity smiley
                  • 9995
                  • 1,613 Posts
                  I think i'm close:

                  I have datepicker js working, added the dob field but it's not saving into the users database.

                  My call:
                  [[!Register?
                    &submitVar=`registerbtn`
                    &activationResourceId=`9`
                    &activationEmailTpl=`myActivationEmailTpl`
                    &activationEmailSubject=`Bedankt voor uw aanmelding!`
                    &submittedResourceId=`8`
                    &usergroups=`Protected`
                    &validate=`nospam:blank,
                    username:required:minLength=^3^,
                    password:required:minLength=^3^,
                    password_confirm:password_confirm=^password^,
                    fullname:required,
                    email:required:email`
                    gender:required:gender`
                    &placeholderPrefix=`reg.`
                    &preHooks=`formatDob`
                  ]]



                  My Dob form field:

                  <div class="fields">
                          <label for="dob">Geboortedatum</label> 
                          <input type="text" name="dob" id="dob" value="[[+dob:date=`%Y-%m-%d`]]" />
                          [[!If? &subject=`[[!+error.dob]]` &operator=`!empty` &then=`<span class="ster">*</span>`]]
                  </div>


                  I have also made the Snippet Kristoffer was talking about on the other topic.

                  Anyone knows whats going wrong?


                    Evolution user, I like the back-end speed and simplicity smiley
                    • 16348
                    • 64 Posts
                    You shouldn't need BobRays posthook, I'm using my solution in the linked post on my site and it works great.

                    Do you have an extra backtick in the end of line line 16 in your snippet call? That could possible break the preHook. The dob is stored as a unix timestamp and my prehook formats a "human-readable" date to a timestamp.
                    If that's not the problem, try to minimize the problem. Disable the datepicker and remove the prehook. Then enter a timestamp directly in the form field and see if that is saved.
                    If you want to see if the hook is working then change the snippet code to something like this:
                    <?php
                      $dob = $hook->getValue('dob');
                      $dob2 = strtotime($dob);
                      $hook->addError('dob','Before hook: ' + $dob + ' After hook: ' + $dob2);
                      return false;
                    

                    That should throw a validation error with the input and output values of the hook as error message.
                      • 3749
                      • 24,544 Posts
                      Agreed. Looking at the code, it wants a user readable date string as input, so as long as that's what shows up on the screen in the form, it should work with no postHook at all.

                      I'm deleting the code I posted above to avoid confusing people.



                      ------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using.
                      MODX info for everyone: http://bobsguides.com/modx.html
                        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