It seems having a required field in the registration form causes the login of an existing user to be blocked unless they fill out the required field at cart checkout as anonymous user.

steps to reproduce:

1. Add a required field to the default Drupal account settings (/admin/config/people/accounts/fields)
2 Make sure "allow registration" is active on the Login pane of the checkout flow of your store (/admin/commerce/config/checkout-flows)
3. Make sure you're not logged in, then add a product to your cart as an anonymous user
4. Go to cart->checkout
5. The Login page should now show, asking you to either log in or register as a new customer. The new customer form should contain the required field created in step 1
6. Attempt to log in as an existing user

result:
The browser blocks the submit of the form, because the field has the attribute required="required" (see attached screenshot)

expected:
The login form should still be submitted and the user logged in, even though the registration form shown on the same page contains a required field.

This bug was introduced since release 2.12, probably due to feature https://www.drupal.org/node/2921312 being merged. The problem I guess is that all the inputs on this page are wrapped in one single HTML form element, thus clicking any of the submit buttons on the page will cause the browser to check all inputs for the "required" attribute.

The solution probably is to wrap each subform into their own form element, so they are independent also from the browsers point of view?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jwwj created an issue. See original summary.

jwwj’s picture

If someone can point me in the direction where I should look into maybe splitting up the forms into their own separate html, then I could try to create a patch to see if it solves the issue. Theming in Drupal is still something of a black box for me, so I'm struggling with figuring out where these commerce forms are actually generated...

Martijn de Wit’s picture

jwwj’s picture

I worked around this for now by having a custom FieldWidget that has it's own "required" validation, which allowed me to set the field as not required in the Drupal built in configuration settings and still have it enforced upon submit. Not pretty, but...

Still think the correct way to solve this would be to split the forms so they would all be wrapped in their own form tag...

Ice-D’s picture

Struggling with the same issue. This should probably be fixed since it's not uncommon to have required fields in registration.

yonailo’s picture

Same problem here, any clues what would be the best way to solve this issue ?

jidrone’s picture

Status: Active » Needs review
FileSize
805 bytes

Here is a small patch for that.
Just to mention it was needed to set the #submit property for submit button as an empty array to be able to use #limit_validation_errors, see FormValidator::determineLimitValidationErrors

jidrone’s picture

Sorry, I forgot to set the parent checkout pane as a dynamic value.

jwwj’s picture

The patch in #8 seems to fix the original issue, thanks! Tested against Drupal 8.7.7 / Commerce 2.14

bojanz’s picture

bojanz’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Fix makes sense.

Let's add a failing test as well. Adding tag.

czigor’s picture

czigor’s picture

Added the #limit_validation thing to the "Continue as Guest" submit button too.

bojanz’s picture

Status: Needs review » Needs work

The fix is good, the test isn't.

We need to test the case from this issue, a required field added to the register form, and then ensuring that Login is possible.

czigor’s picture

Status: Needs work » Needs review

That's what the test is doing. The test was already adding a required field to the user register form so I did not have to change that. However, due to the login pane's configuration the user registration form did not appear on checkout. That's what was fixed by setting both the allow_registration and allow_guest_checkout settings to TRUE.

czigor’s picture

bojanz’s picture

Title: Required fields on new customer form validated at cart checkout login » Required fields on the registration form validated at checkout login
Version: 8.x-2.12 » 8.x-2.x-dev

  • bojanz committed 73c6d89 on 8.x-2.x authored by czigor
    Issue #3035519 by czigor, jidrone, jwwj: Required fields on the...
bojanz’s picture

Status: Needs review » Fixed

Tweaked the #limit_validation_errors for login to not assume that there's only a single pane form parent, and committed.

Thank you jidrone and czigor!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

MegaChriz’s picture

This did broke a custom form alter on this form: I had added an extra field (email) to the guest fieldset and I noticed that:

  • Validation of this extra field got ignored.
  • In the submit handler, the values from the extra field were missing.

@czigor (re #13)

Added the #limit_validation thing to the "Continue as Guest" submit button too.

I'm not sure if limit validation errors in the guest fieldset were also needed?