craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.22k stars 626 forks source link

[4.4]: Custom field validation stopped working on front-end #12884

Closed pdaleramirez closed 1 year ago

pdaleramirez commented 1 year ago

What happened?

Description

Adding a required custom field to an Element stopped validating when saving the field on a front-end form after upgrading to CMS version 4.4

Steps to reproduce

  1. Create a plain text custom field with a handle of "description".
  2. Add the created field to the User Fields field layout and make it required.
  3. Create a front-end Registration Form
  4. Add the custom field as a twig input
        {{ user ? _self.errorList(user.getErrors('description')) }}
        <label for="description">Description</label>
        {{ input('text', 'fields[description]', null, {
            width: 11,
            class: [
                'w-48',
                'border border-gray-300 hover:border-gray-500 px-4 py-2 leading-tight rounded',
            ],
        }) }}
  5. Hit the Register button.

Expected behavior

It should not save the user and display the validation error of "Description cannot be blank."

Actual behavior

It saves the user and no validation error text is displayed.

Craft CMS version

4.4

PHP version

8

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

-

i-just commented 1 year ago

Hi Dale, I’m unable to replicate this. If the Settings > Users > Settings > Validate custom fields on public registration is checked and the custom field is required, it gets validated on registration. Are you able to replicate it with this option turned on?

That being said, I can replicate the related Commerce issue #3109 on Craft 4.4 but not on Craft 4.3.9 (using the same version of Commerce in both cases, 4.2.4 Pro), and I see what causes it. I'll update this issue again once the fix is ready.

i-just commented 1 year ago

PR submitted.

pdaleramirez commented 1 year ago

Hi Dale, I’m unable to replicate this. If the Settings > Users > Settings > Validate custom fields on public registration is checked and the custom field is required, it gets validated on registration. Are you able to replicate it with this option turned on?

That being said, I can replicate the related Commerce issue #3109 on Craft 4.4 but not on Craft 4.3.9 (using the same version of Commerce in both cases, 4.2.4 Pro), and I see what causes it. I'll update this issue again once the fix is ready.

Thank you for checking; it is my fault, my project config did not make the custom field back to "required" when changing databases.

i-just commented 1 year ago

Cool, thanks for the update Dale!