Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
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!
Comment | File | Size | Author |
---|---|---|---|
#15 | 1348384.15-commerce-customer-profile-validation-error.patch | 892 bytes | mrfelton |
#12 | 1348384.12-commerce-customer-profile-validation-error.patch | 871 bytes | mrfelton |
#1 | checkout-errors-validation.jpg | 150.01 KB | pcambra |
validation email.png | 74.05 KB | jens.de.geit |
Comments
Comment #1
pcambraWhat 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.
Comment #2
pcambraComment #3
rszrama CreditAttribution: rszrama commentedYeah, 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.
Comment #4
jens.de.geit CreditAttribution: jens.de.geit commentedNo 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
Comment #5
John Pitcairn CreditAttribution: John Pitcairn commentedReopening 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)
Comment #6
rszrama CreditAttribution: rszrama commentedIt 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.
Comment #7
agileadamI 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.
Comment #8
agileadamOut 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.
Comment #9
rszrama CreditAttribution: rszrama commentedYep, that module works through hook_field_attach_validate().
Comment #10
agileadamSo, my question is, how do we address this? It's seems like an issue that will affect many sites. Thanks!
Comment #11
mrfelton CreditAttribution: mrfelton commentedI 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.
Comment #12
mrfelton CreditAttribution: mrfelton commentedThe 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.
Comment #13
mrfelton CreditAttribution: mrfelton commentedComment #15
mrfelton CreditAttribution: mrfelton commentedUpdated patch to fix "Invalid argument supplied for foreach()" warnings highlighted by the test exceptions.
Comment #16
g089h515r806 CreditAttribution: g089h515r806 commented#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.
Comment #17
rszrama CreditAttribution: rszrama commentedAlrighty, 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!)
Comment #19
tintisha_andy CreditAttribution: tintisha_andy commentedDoes 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 :)
Comment #20
rszrama CreditAttribution: rszrama commentedThis 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.
Comment #20.0
rszrama CreditAttribution: rszrama commented*
Comment #21
narendrathakur CreditAttribution: narendrathakur commented...
Comment #22
ropic CreditAttribution: ropic as a volunteer commentedThis problem continues also using email field on commerce registration