Am following the progress of webform_registration for D7 port - http://drupal.org/node/1336486- but wondering if it can all be achieved via Rules instead. Thoughts?

Comments

stborchert’s picture

Hm yes, I think this should be possible.
If you're using the action "Execute custom PHP code" you have full access to all data entered in the webform so you can create a new user object and call user_save().

Example:

<?php
$userinfo = array(
  'name' => $data['components']['username']['value'],
  'pass' => user_password(), // Generate password
  'init' => $data['components']['username']['value'],
  'status' => 1,
  'access' => REQUEST_TIME
);
$account = drupal_anonymous_user();
$account->is_new = TRUE;
user_save($account, $userinfo);
?>
petednz’s picture

thank you for your reply - i will try and give that a go and report back

stborchert’s picture

Status: Active » Closed (fixed)

Please reopen if there are further questions.

hansrossel’s picture

This is working when using civicrm, but the validation if a user or email allready exists is not functioning correctly (no message, just an unhelpful error).

$userinfo = array(
  'name' => $data['components']['login']['value']['0'],
  'pass' => user_password(), // Generate password
  'init' => $data['components']['civicrm_1_contact_1_email_email']['value']['0'],
  'mail' => $data['components']['civicrm_1_contact_1_email_email']['value']['0'],
  'status' => 1,
  'access' => REQUEST_TIME
);
$account = drupal_anonymous_user();
$account->is_new = TRUE;
user_save($account, $userinfo);
jazzitup’s picture

You should provide your own validation for it, eg:

  $name = 'my_username';

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

  if($user) {
    print "ERROR: Username already exists.";
  }
  else {
    print "Yay, username is available!";
  }