I would like to create user account using rules, after anonymous user creates a node and inputs his email to a email field. Before that I need to run a condition if the email is already in use. What would be the easiest way of doing this? Using fetch entity by email or using custom php? I read about user_authenticate function but I do not know how to use it. Thank you for advice.

    ->condition('mail','user email comes here','=')

    form_set_error('mail','Email Already Exists');

You can use this.

|improve this answer|||||
  • Hi, I put this code to custom php condition in rules like this $check=db_select('users','u') ->fields('u',array('uid')) ->condition('mail','[node:field_email]','=') ->execute() ->fetchField(); if($check!='') { return FALSE; }. Replaced email with email field pattern, but it always returns false. Even if email does not exist. – loparr Jul 21 '14 at 15:12
  • I even tried to replace email with $node->field_email['0']['value'] but no luck – loparr Jul 21 '14 at 16:18
  • Have you checked Email value is coming in $node->field_email['0']['value'] or [node:field_email]. – TBI Infotech Jul 22 '14 at 4:07
  • Hi, php code does not take tokens. Correct value was $node->field_email['0']['email'] (based on devel info). Anyway your code did not work for me. Instead I used this answer stackoverflow.com/a/6492473/1031742 – loparr Jul 24 '14 at 1:36

Add a Rules Component that takes a list of users as a parameter and put all the actions in this component. Add a list count comparison condition as less than 1. In the original rule Fetch entity by property of type User with the email address you need to check. Pass the list that is fetched to the Rules Component as the parameter. Only if no users exist with that email address will the actions of creating a new account happen.

|improve this answer|||||

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.