I have downloaded a Registration Module and added a username and password fields to the form.

I am trying to call the Save_User function from within the hook_form_alter() as shown in the code.

However I keep getting message "duplicate entry '' for key 'name' insert into users". This led me to see that the field $form_state['value']['field_username'] was empty, that is the value is not being passed in the Post action. I ahve also tried

function mymodule_form_alter(&$form, &$form_state, $form_id)
{
if (isset($form['actions']['submit'])) {
$form['actions']['submit']['#submit'][] ='mymodule_form_submit';

}
return $form;
}

function mymodule_form_submit(&$form, &$form_state)
{
$user_info = array(
'name' => $form_state['value']['field_username'],
'pass' => $form_state['value']['field_confirm_password'],
'mail' => $form_state['value']['field_email'],
'status' =>1,
'init' => $form_state['value']['field_email'],
);
user_save(null, $user_info);

}

Note: I have also tried:

$user_info = array(
'name' => $form_state['values']['field_username'],
'pass' => $form_state['values']['field_confirm_password'],
'mail' => $form_state['values']['field_email'],
'init' => $form_state['values']['field_email'],
'status' =>1,

Comments

Stefan Lehmann’s picture

Install the devel module and add dsm($form_state); before you try to extract data from that array. That will output an expanded version of the results array. Very helpful when debugging.

I like cookies!