Search code examples
drupaldrupal-7

Drupal 7 New User Creating programmatically?


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'] = 'robouser@example.com';
$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?


Solution

  • 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.