Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x]: User's Last Name field letter casing lost when saved via front-end form #14723

Closed
vonscriptor opened this issue Mar 28, 2024 · 6 comments

Comments

@vonscriptor
Copy link

What happened?

Description

I've read the past issues dealing with Full/First/Last Names, but am a little unclear on how to handle the following:

Let's take last name "van holtz" as an example. I want it always shown as Van Holtz. However, say another person with the same last name wants it displayed as "van Holtz". Craft's Last Name field seems inconsistent on how it handles this. It lower-cases the "van" when saved via a front-end form, but does maintain casing when saved from the CP. I thought maybe including both in extraLastNamePrefixes might work, but it seems to only go with one.

Note: The Full Name field correctly uses the written case even from a front-end form (even when a "Full Name" field isn't provided and it's generated automatically).

Consideration: Due to how I want to present a user's name on the website I need it to be in 2 parts (first, last) so that I can output and style them individually (I need them on 2 lines).

Steps to reproduce

  1. Set general.php 'showFirstAndLastNameFields' => true,
  2. Create a front-end form that can save a user's Last Name
  3. Save the last name with something like "Van Holtz"

Expected behavior

The letter casing of the last name should be kept when saving from a front-end form like it is in the CP. Whether or not the user wants something like "Van Holtz" or "van Holtz".

Actual behavior

The "Van" in "Van Holtz" is saved as "van Holtz".

Craft CMS version

4.8.6

PHP version

8.1.27

Operating system and version

MacOS Sonoma 14.3.1

Database type and version

MySQL 8.0.30

Image driver and version

No response

Installed plugins and versions

  • Freeform v5.1.8
@brandonkelly
Copy link
Member

Craft isn’t doing anything to alter the casing, and neither is the name parsing library we use, as far as I can tell. Name casing is preserved on my end whether I submit separate firstName and lastName values, or a single fullName value.

Maybe you have something in your JavaScript that is normalizing names on form submit? Or a plugin/module that is doing something?

@vonscriptor
Copy link
Author

You're right, seems like a Freeform issue. Thank you!

@vonscriptor
Copy link
Author

@brandonkelly Some additional information from the Solspace team regarding this issue can be found in the discussion linked below.

I went through everything with XDebug to see what causes the name change, and it happens on the \craft\elements\User::afterSave() method, which gets called by Craft's Elements service's save() method.
In it, it calls a prepareNamesForSave() trait method, which runs the submitted name through a parser, and comes up with van Holtz from the Van Holtz that was input by me.

solspace/craft-freeform#1181 (reply in thread)

brandonkelly added a commit that referenced this issue Apr 19, 2024
@brandonkelly
Copy link
Member

Sorry! I’m able to reproduce now. I’m not sure why I couldn’t earlier… I think I might have been testing the opposite of what you were saying – ensuring that lowercased van wasn’t getting uppercased to Van.

Just got this fixed for the next release.

@vonscriptor
Copy link
Author

@brandonkelly Great, thank you so much!

@brandonkelly
Copy link
Member

Craft 4.8.10 and 5.0.5 are out with that fix. Thanks for bearing with me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants