I wanted to do exactly the same thing.
This code has worked for me.
Add a prehook to the registration form
$fullname = $hook->getValue('firstName').' '.$hook->getValue('lastName');
In the html
<input type="hidden" name="fullname" id="fullname" value="[[!+firstName]] [[!+lastName]]" />
Perfect. Andy, you are a star!
That's fantastic, thank you very much.
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.
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?
There are a couple of conversations about this.
I can't look into it right now, but will do so later, as I need to sort it on my own site!
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.
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.
Ah, are you doing this on the update profile page?
I agree that there should be firstname and lastname fields. I think almost everyone who uses MODX would agree.
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
It should also contain this somewhere
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 1 year, 2 months ago.]