On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I need two extended fields, "firstname" and "lastname", but I don't want to have additional the built in field "fullname". How can I combine the two separate fields in the field "fullname"? [ed. note: istvan.velsz last edited this post 9 years, 5 months ago.]
    • I've done this in two different ways. One was to use Javascript to populate a hidden field with the content of the two fields. The second was to have the form's processing combine the two fields.
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
      • Thanks, I solved it with some Javascript
        • Just to any future readers - I now understand that Mark Hamstra has added this as a feature request (http://tracker.modx.com/issues/7695) - personally I think adding a salutation would not be a bad idea either I will try and add to the request.

          Anyway here is the (jQuery) javascript I used to combine my extended fields for first and last into full name. The event is triggered on form submit.

          (NB obviously change form / field names to match yours)

          Nasty hack but works for the time being...

          <script type="text/javascript">
          $(document).ready(function() {
          	$("#reviewer_register_form").submit(function() {
          		$fullname = $("#First").val() + " " + $("#Last").val();
          		// un-coment to debug alert("done");
          		return true;
          • I'm facing this issue currently.

            With the above, if there's validation on first and last names, and the user leaves one of them blank, how do I pre-populate value=""
            • I have been using this code as a hook for the Register and UpdateProfile snippets for some time to do the same thing:
              $firstname = $hook->getValue('firstname');
              $lastname = $hook->getValue('lastname');
              $fullname = $firstname . ' ' . $lastname;
              return true;
              • Thanks Kristoffer, I will try this now.

                Is the a pre or post hook?
                • ok, it's a post hook

                  This is working now - really appreciate you pointing me in the right direction.



                  didn't work. The debug code showed that $fullname was set correctly but setValue wasn't saving.

                  But your solution led me to uncover http://forums.modx.com/thread/?thread=72933&page=1 which took a different approach

                  $profile = $hook->getValue('register.profile');

                  which worked.

                  Still be interested to know why setValue works for you though.
                  • Sorry, I should have said that my code should be used as a pre hook.
                    The pre hook is executed before the fields array are saved to the database so all edits to that array in the hook should be saved.

                    Glad that it worked anyway.