Problem/Motivation

1. We have a shipping and a billing customer profile to fill out on checkout.
2. Billing profile has the "copy from shipping" checkbox checked by default.
3. Shipping profile has fields with #elment_validate callbacks.

In this case the #element_validate callbacks run twice: once for the shipping profile and once or the billing profile. This results in two identical form validation error messages, although the second form is hidden (by #access=FALSE).

Original issue

Hello,

I'm looking for advice on the use case below.
In shipping and billing customer information, instead of the name within the address field, we use a name field, as provided by Name module. This provides us a lot more options to the name field (salutation, and others).
The same name field is added to both shipping and billing information.
We set the shipping address first, and billing address has Enable profile copying on this checkout paneoption checked, and copy from set to shipping.
On the checkout form, My Billing information is the same as my Shipping information. is checked by default, now, when I submit the form, although copy is checked, I get a validation error Name is required..

The reason is probably that Name module checks the emptiness of a field at the "element_validate" level, whereas commerce_customer module handles "shipping > billing copy" later, at the form validate level.

Now I've tried many things, such as implementing hook_element_info_alter() to unshift my own custom element validate that will be able to call form_set_value() when necessary, before name_element_validate() is actually called, but even this does not work.

Any suggestion?

Thank you in advance,
David

Comments

rooby’s picture

Title: Name module is not compatible with Profile copy options » Profile copy is not compatible with fields that implement #element_validate
Version: 7.x-1.5 » 7.x-1.x-dev
Category: Support request » Bug report
Issue summary: View changes

This is not specific to the name field, although the name field is affected.

The issue is with fields failing the element validate call before the profile values have been copied.

Copy needs to happen earlier or else initial validation needs to be suppressed in some way and then run after the copying of the profile values.

rooby’s picture

Actually maybe I'm wrong. I'll have to do a little more investigation.

rszrama’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

Yeah, I think we'll need more info here, because when the profile copy box is checked, the element shouldn't appear on the form at all or trigger validation.

czigor’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active

I have the same issue with custom #element_validate functions.

The issue is that #access = FALSE does NOT stop #element_validate callbacks from running, see the end of _form_validate().

On the other hand, if a field is only #required = TRUE and #access = FALSE then I suspect that #needs_validation is not TRUE so the field won't complain.

Should we use #limit_validation_errors in commerce_customer_profile_pane_checkout_form() maybe?

rooby’s picture

In some cases for me it was the name field continuing to throw validation errors for the copied values after they were fixed in the source profile.
I seem to have fixed that with the patch in #2521082: Customer profile copy create empty copy if source validation fail