1

I'm currently trying to implement a function to check if a user already exists. I've read that this could be done by Rules whit the condition "Entity exists by property" but I can't find it anywhere. I've tried it with Rules 7.x-2.2 & Rules 7.x-2.3

Is this option still available or not? Or is it located in a other module?

it's related to this question: How can I check whether a username is in use?

1

If you check this issue you will see that the condition has not yet been added to Rules. A patch is available if you wish to test it.

1
  • 1
    It's a website with different groups. Each group has the ability to add users to the system. This is done with a content node and the Rules action "create new entity". I could get the patch to work got a error on a entity function. But that patch helped me create a own module with a rule and some custom code. – Rik May 28 '13 at 13:15
2

Drupal 7 has a function to return a user object by username:

$user = user_load_by_name($name);
if(!$user){
    // User doesn't exist
} 
else {
    // User exists
}

function user_load_by_name

And a function to return a user object by email:

function user_load_by_mail

0

Assuming you want to check for the existence of a username for new users (who are registering), there is a module that implements that functionality, albeit in 7.x-1.x-dev status... It's kind of hard to find because the name is a little complicated, but you might give it a try or even just look at the source code to get a feel for the way that module checks for username existence. It's called Username originality AJAX check.

0

Use this snippet and you can check whether the user selected name is available or not.

$name = 'user_selected_name';

$user = db_select('users', 'u')
    ->fields('u', array('name'))
    ->condition('u.name', $name, '=')
    ->execute()
    ->fetchAssoc();

    if($user) {
        print "user exists";
    }
    else {
        print "Name is available, You can take it.";
    }

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.