We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40088
    • 708 Posts
    Revo 2.6.2

    On my registration form I chose to disable the default "fullname" field and replace it with "first" and "last" name fields instead. It works fine.

    With regard to managing users from the Manager the "fullname" field is obviously quite useful so I'm wondering if there's a way to grab and combine the "first" and "last" name values from the Registration form and use them as the value for the "fullname" field.

    I realize I could display the "first" and "last" names as extended fields on the user Manager page but if possible I would prefer to make use of the "fullname" field since it's already there.

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

      Todd
    • discuss.answer
      • 38783
      • 571 Posts
      I wanted to do exactly the same thing.

      This code has worked for me.

      Add a prehook to the registration form
      &preHooks=`fullname`


      The fullname snippet code
      <?php
      $fullname = $hook->getValue('firstName').' '.$hook->getValue('lastName');
      $hook->setValue('fullname',$fullname);
      return true;


      In the html
      <input type="hidden" name="fullname" id="fullname" value="[[!+firstName]] [[!+lastName]]" />


        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
        • 40088
        • 708 Posts
        Perfect. Andy, you are a star!

        That's fantastic, thank you very much.
          Todd
          • 40088
          • 708 Posts
          Andy,

          Your solution works perfectly with the Register snippet but I just noticed that when using the UpdateProfile snippet to uh... update the user profile from the front-end, that editing either the "first" or "last" name fields does not update the "fullname" field on the Manager > Users page.

          I added the &preHooks property and hidden text field to the UpdateProfile form but it doesn't seem to have any effect.
            Todd
            • 38783
            • 571 Posts
            It looks like I have the same problem on my website!

            I think it makes sense. It is related to the sequence of events. The new firstname and lastname have not been submitted when the prehook fetches them. On my site it appears that if you update the profile twice it puts the new firstname or lastname into fullname.

            Would making the prehook a posthook work?

            I not I think it might be necessary to use Javascript to capture the new firstname or lastname field contents.

            There are a couple of conversations about this.
            https://forums.modx.com/thread/73670/solved-combine-extended-fields-first--lastname-in-fullname
            https://forums.modx.com/thread/44821/manipulating-registration-data-in-a-prehook-snippet

            I can't look into it right now, but will do so later, as I need to sort it on my own site!
              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
              Since firstname and lastname are not actual fields anywhere, updating them won't have any effect. You could make them extended fields. Or you could use JavaScript to update the hidden fullname field whenever they change.

              A simpler option would be to just use the fullname (no first of last input) after the user has registered and let the user update that. You could extract the first and last names with a snippet whenever you needed it. Since you got them separately in Register, you don't have to worry about middle names and the like.

              You could also use ClassExtender to add those new fields, but that seems like overkill for the use case.
                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
                • 40088
                • 708 Posts
                I did use ClassExtender to add "firstName" and "lastName", and while redundant it does simplify a couple things but clearly doesn't solve this current problem.

                Out of curiosity how could they be extracted with a snippet?

                The entire reason for using "firstName" and "lastName" is to ensure people actually enter two names. The "fullname" field is too easy to dismiss.

                Honestly, I find it quite strange MODX doesn't default to "first" and "last" instead of fullname. If it did it would make all of this hoop-jumping entirely unnecessary. Maybe in MODX 3.0.
                  Todd
                  • 3749
                  • 24,544 Posts
                  Ah, are you doing this on the update profile page?

                  [[!ExtUserUpdateProfile]]
                  [[!UpdateProfile]]


                  I agree that there should be firstname and lastname fields. I think almost everyone who uses MODX would agree. wink
                    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
                    • 38783
                    • 571 Posts
                    I realised that my problem was that I had omitted the prehook from my profile update page. Now that I have it in place the update profile page works correctly and updates the Full Name using the first and last name fields.

                    Could you post the code for your update profile page?

                    It should start with
                    [[!ExtUserUpdateProfile]]
                    [[!UpdateProfile? 
                    &useExtended=`0`
                    


                    It should also contain this somewhere
                    &preHooks=`fullname`


                      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
                      • 40088
                      • 708 Posts
                      Thanks Andy, it's working now. I was using the hidden text field and that was preventing fullname from updating. [ed. note: todd.b last edited this post 5 years, 11 months ago.]
                        Todd