0

I am using latest commerce module with D7 site. By default commerce displays form errors inside individual commerce checkout form panes. This is designed by default and every pane has it's own validation callback. So this is different from Drupal's form API error displaying.

Is it possible to display them at the top of the form, same as Drupal form API does it? Does form_set_error works well for all checkout form elements and they get error class? (it seems to not work for me).

2 Answers 2

1

As Ryan mentioned, it's difficult to change that behaviour server-side, however you could move the error messages to the top of the page with JavaScript instead.

e.g

style.css

/* Hide checkout messages by default to show with JS later */
body.page-checkout .messages{
  display:none;
}

script.js

Drupal.behaviors.moveCheckoutMessages = function (context) {
  $('body.page-checkout form .messages', context).each(function () {
    $('.region-content').prepend($(this));
    $(this).css({"display":"block"});
  });
}

A client-side approach like that should work.

1
  • nice approach with minimal work. Thanks for your suggestion, will absolutely try that! Commented Jul 12, 2014 at 13:09
0

Given the way we developed the checkout form as a composite of checkout pane "sub forms", it isn't possible to change the way we're trapping and displaying error messages. You would need to create a drop-in replacement for the checkout form.

2
  • ok, so this is the way you designed commerce checkout forms. Is this way more user friendly as errors are displayed near elements? Just curious how you made this decision - user testing or something similar? Commented Jul 12, 2014 at 13:15
  • 1
    Yes, the idea is to put the error messages as close to the offending form elements as possible. Checkout forms can get quite long, so by the time you scroll to a form element that had a problem, you may have forgotten the error message. Commented Jul 14, 2014 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.