Reputation: 18325
Drupal 7 i need to crate New User with the Code (not via the Panel manually).
When i test with this chunk of example code i googled, in the Drupal:
$form_state = array();
$form_state['values']['name'] = 'robo-user';
$form_state['values']['mail'] = '[email protected]';
$form_state['values']['pass']['pass1'] = 'password';
$form_state['values']['pass']['pass2'] = 'password';
$form_state['values']['op'] = t('Create new account');
drupal_execute('user_register', $form_state);
It showing: Fatal error: Call to undefined function drupal_execute() in ......
How can i make it work or any other simple way like above?
Upvotes: 2
Views: 3620
Reputation: 143
Try this, which really handles programmatically rather than mimicking the user registration behavior.
$account->is_new = TRUE;
$account->status = TRUE;
$edit['name'] = $name;
$edit['mail'] = $mail;
$edit['status'] = 1;
$edit['init'] = $name;
$newuser = user_save($account, $edit);
//send email if you want
_user_mail_notify('register_no_approval_required', $newuser);
Upvotes: 5
Reputation: 12238
The example code you found is for Drupal 6 and out-of-date. drupal_execute()
was renamed drupal_form_submit()
in Drupal 7 and the form is now user_register_form
.
Upvotes: 3