I have a email field on my customer profile the validation of the 'required field' is correct but the email validation doesn't get fired.

ow yeah this is in the checkout procedure!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pcambra’s picture

FileSize
150.01 KB

What kind of field are you using for the email?

I've just installed email field project http://drupal.org/project/email and I get the validation errors as expected.

pcambra’s picture

Status: Active » Postponed (maintainer needs more info)
rszrama’s picture

Category: bug » support
Status: Postponed (maintainer needs more info) » Closed (works as designed)

Yeah, if you've just used a textfield for that, Drupal has no way of knowing it should apply e-mail validation to it. You'd have to use the field pcambra linked to above if you want actual e-mail validation.

jens.de.geit’s picture

No its a e-mail field so the validation should be correct, if I go in the backoffice to the form (Billing information) the validation works fine.

Version of the email module is 7.x-1.0

John Pitcairn’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Category: support » bug
Status: Closed (works as designed) » Active

Reopening this. I have an email field added to customer billing information. The field is not a text field, it's an email field: http://drupal.org/project/email (which uses a text widget, that's all it provides).

Email field validation via email_field_validate() runs, and an error message is set, but the commerce checkout form ignores that and continues to submit.

See also #1608354: How to prevent form submit if email is invalid (no responses)

rszrama’s picture

Category: bug » support

It seems to me there might be a bug in the Field API itself; we need to dig deeper, but the issue here is that the email module only implements hook_field_validate(), not hook_field_widget_validate(). hook_field_validate() doesn't appear to be setting form errors earlier enough when field_attach_form_validate() is called by the customer profile checkout pane's validate callback, but if a field (like the Price field) implements hook_field_widget_validate(), then it gets caught and stopped just fine.

agileadam’s picture

I can confirm that the Phone module behaves similarly. I've added a phone field to my customer billing profile. The field is validated and I get an appropriate error message (thanks to http://drupal.org/node/1715380#comment-6496918), however, I'm allowed to continue and I'm taken to the next page in the checkout process. Phone implements hook_field_validate() as rszrama mentioned in comment #6.

agileadam’s picture

Out of curiosity I created a new text field with a regex validator (using http://drupal.org/project/field_validation). That module flags the error, but I am taken to the next screen in the checkout process.

rszrama’s picture

Yep, that module works through hook_field_attach_validate().

agileadam’s picture

So, my question is, how do we address this? It's seems like an issue that will affect many sites. Thanks!

mrfelton’s picture

Priority: Normal » Major

I have exactly the same problem as @agileadam. Text field with Field Validation regex validator. This is a major problem for us as we have a one page checkout process. As is now, the order ends up being submitted, even though there is an error on the form. This can lead to all kinds of error like orders being left in incorrect state, or payment being submitted, but order is complete rule not firing. If there is a validation error, then the form should not be submitted.

I have noticed that if there are 2 errors on the form - one in the address field, and one in our custom field on the billing profile, then both errors are shown. If there is only one error (on the custom field), then the error is not shown and the order is submitted, the user gets a thank you email, but no payment is actually taken, and the order paid in full fule never fires, resulting in people thinking they have made a successful order (account created, notified by email) but no actual payment was made.

mrfelton’s picture

Status: Active » Needs review
FileSize
871 bytes

The problem here seems to actually lay in he commerce_customer_profile billing pane's validation handler, which fails to return FALSE when there is a validation error on one of the fields. This means that validation errors from field_attach_form_validate do not actually stop the commerce checkout process from continuing. Checkout panes must return FALSE in order to halt the checkout process.

Attached patch resolved, although there may be a more graceful way to detect if the customer profile form had an error.

mrfelton’s picture

Category: support » bug

Status: Needs review » Needs work

The last submitted patch, 1348384.12-commerce-customer-profile-validation-error.patch, failed testing.

mrfelton’s picture

Status: Needs work » Needs review
FileSize
892 bytes

Updated patch to fix "Invalid argument supplied for foreach()" warnings highlighted by the test exceptions.

g089h515r806’s picture

#15 is correct.
In field collecton module, fago also use "form_get_errors()" to prevent submit when there is any errors in field collection form.
Commerce also need to add similar logic.

  if ($form_state['submitted'] && !form_get_errors()) {
rszrama’s picture

Priority: Major » Normal
Status: Needs review » Fixed

Alrighty, let's go ahead and fix this here; the API is simply deficient. Would be nice if field_attach_form_validate() returned a boolean itself, but checking the form errors is indeed the next best thing. Only fix to the patch was to swap out the actual current checkout pane ID instead of hardcoding commerce_customer_billing to make sure it works for other customer profiles types.

There may be other modules that expose fields to checkout panes (e.g. Commerce Fieldgroup Panes) that need this same fix if anyone feels like being generous. : )

Commit: http://drupalcode.org/project/commerce.git/commitdiff/0208b42 (credit to mrfelton - thanks!)

Status: Fixed » Closed (fixed)

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

tintisha_andy’s picture

Does this patch also fix the issue for fields in an order that are not part of a customer profile? I have an email field and a date field that need to validate. An email field within a customer profile will error as expected if an incorrectly formatted email address is entered, but the email field that I added to the order form that isn't part of a customer profile the validation seems to be ignored.

I have applied the patch but the validation still seems to be ignored.

I hope that makes sense :)

rszrama’s picture

This patch is already part of Drupal Commerce; see comment #17 where it was committed. What you're talking about exists in a separate issue, so I'd give the queue a search. I can't remember the title, but it has to do with the hooks used to validate different field types.

rszrama’s picture

Issue summary: View changes

*

narendrathakur’s picture

Issue summary: View changes

...

ropic’s picture

This problem continues also using email field on commerce registration