In Drupal Commerce, how to prompt a warning message and keep it in checkout process if an anonymous inputs a registered email? I know there is a Commerce Checkout Login, but it is just an AJAX addon.

I believe I can do it through Rules and that's what I did.

  • Event: Process checkout pane
  • Conditions:
    • Data comparison: [commerce-order:uid] == 0
    • NOT Data value is empty: [commerce-order:mail]
    • Entity exists by property: User/Email, [commerce-order:mail]
  • Actions:
    • Show a message on the site: Warning, ...
    • Update checkout status: checkout

In first trial, it seems work well. But the weird thing is, when I change the email field to an unregistered one, I can still spot the warning message generated by Show a message on the site. Is there something wrong in my rule setup?

Refer to this Anonymous can use registered email address: intended behavior?.

  • Are you sure that commerce isn't creating user profiles upon checkout? Some implementations do that for anonymous users... Dec 5, 2013 at 22:27
  • Yes, it does. But what I am looking for is to prevent the creation of user profiles when anonymous inputs a registered email. Otherwise, anonymous can create an order. Refer for to drupal.org/node/1469946, what I exactly like to solve.
    – Drake Guan
    Dec 6, 2013 at 0:31
  • You mentioned Commerce checkout login it will solve that issue by allowing the user to login if they enter a registered email address. Dec 6, 2013 at 1:37
  • Commerce checkout login does that job well. But anonymous can just ignore it and keep the checkout, which is what I like to prevent.
    – Drake Guan
    Dec 6, 2013 at 8:37
  • 2
    This isn't an answer, so I'll just leave it as a comment: I wouldn't do this during Rules. What you want is form validation, not really form post-processing. Why not just hook into this form with hook_form_alter() and make it do exactly what you want without having to work around Rules? Dec 6, 2013 at 14:02

1 Answer 1


With @RyanSzrama's suggestion, I pursue a form validation solution. What I finally use is to implement a hook_commerce_checkout_pane_info_alter. The following is a simplified code snippet for that.

 * Implements hook_commerce_checkout_pane_info_alter
function MYMODULE_commerce_checkout_pane_info_alter(&$checkout_panes) {
    $checkout_panes['account']['callbacks']['checkout_form_validate'] = 'MYMODULE_form_validate';

function MYMODULE_form_validate($form, &$form_state, $checkout_pane, $order) {
  if (!user_is_logged_in()) {
    $mail = $form['account']['login']['mail']['#value'];
    $query = sprintf("SELECT COUNT(*) FROM {users} WHERE mail = '%s';", $mail);
    if (db_query($query)->fetchField()) {
      $msg = t('The email address is registered to an account!');
      form_set_error('[account][login][mail]', $msg);
      return FALSE;
  return TRUE;

Hope that also provides some hint or help to others. For form validation, please refer to Adding validation to commerce pane form.

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.