3

I have created an entityform called "Order Request". This form has fields for the user to enter their first name, last name, email address, and their order contents. I would like to register this anonymous user when they submit this form. I have this working, configured with the Email Registration module and Rules to use these fields to create the new user.

However, the problem is this: Both anonymous and registered users (with the role: customer) need to be able to use the form. I need to prevent an error if there is already an account created using the email address submitted in the form. I would like to check that and not fire the rule to create a new account. How can I create this conditional in my rule? Hope that's clear. Thanks

2

I thought the field validation module should have been able to do this but I couldn't make it validate against the user mail field. Maybe you could try that and have better luck.

The other option which definitely works and requires no coding is to use the Views Bulk Operations (VBO) module and use rules conditions to check the number of results for that email address.

a. VBO Mail Check View

  1. Create a new view page to display users.
  2. Add the "Bulk operations: User" field (no changes needed).
  3. Add the contextual filter, "User: Email" and provide the default, "Raw value from Url, path component 2".
  4. Test with the preview using a valid email address and make sure one result shows before proceeding.

b. New rule condition in your main rule for when the entity form is saved.

  1. "Check number of results returned by a VBO View"
  2. Choose the view and page display you created above.
  3. Send the text field from the entity form as an argument. (This will be path component 2 in the VBO view above)
  4. Set the minimum value to 1.
  5. Negate the condition.

This will make the rule fire if the VBO view returns zero results ie. no email.

c. Create a new rule to show an error if the mail exists.

  1. Same condition as above.

  2. I don't really know why this works but anyways. Add an AND above the condition, negate it and indent the condition which is also negated. (move it to the right like it's a child). It will look like

Entity has field

NOT AND

      NOT Check number of results returned by a VBO View

  1. Action: Display site message and tell the user that the email is already in use.

It looks a bit convoluted but should only take a few minutes to get working. Good luck!

  • Thank You very much for taking your time with this. I had attempted the VBO earlier, but wasn't sure what I was doing. I will try this and let you know. Again, Thank you. – xturgorex Nov 7 '15 at 7:25
  • Clever use of the URL. I've got a lot to learn about views – xturgorex Nov 7 '15 at 19:51
  • 1
    Another answer with that interesting "Check number of results returned by a VBO View", nice! – Pierre.Vriens Feb 17 '17 at 9:53
  • I love Drupal for the interesting GUI solutions available. I just wish I had more time for SE. – Niall Murphy Feb 17 '17 at 15:56
  • Is it necessary for the VBO view to have a page display, or is it enough to have the Master? – mbomb007 Sep 21 '18 at 21:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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