Execute user_save() after the form submission handler In my implementation of hook_form_alter() I am using the following code; it executes mymodule_user_form_submit() before user_save().

array_unshift($form['#submit'], 'mymodule_user_form_submit');


user_save() is not executing after that.

What is the problem with this code?

I want to execute user_save() after mymodule_user_form_submit().

function mymodule_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  if ($form_id == 'user_register_form') {
    drupal_set_message("Form ID is : " . $form_id);
    //$form['#submit'][] = 'custom_user_form_submit';
    array_unshift($form['#submit'], 'mymodule_user_register_submit');
  }

}

function mymodule_user_register_submit(&amp;$form, &amp;$form_state) {
//code goes here
$form_state['field_magentopass']['und'][0]['value'] = $form_state['values']['pass'];
}


if the code is wrong how can i assign the value to this variable $form_state['field_magentopass']['und'][0]['value']

or this entire method is wrong?
should i go for any other alternatives?
In your code, your submit handler ( mymodule_user_register_submit ) and actual function name ( custom_user_form_submit ) are different.

Also, your submit handler is using

$form_state['field_magentopass'] 


instead of

$form_state['values']['field_magentopass']...


It should be something like

/**
 * Implements hook_form_FORM_ID_alter
 * User register form id: user_register_form
 */
function mymodule_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  drupal_set_message("Form ID is : " . $form_id);
  array_unshift($form['#submit'], 'mymodule_user_register_submit');

}

function mymodule_user_register_submit(&amp;$form, &amp;$form_state) {
  $form_state['values']['field_magentopass'][LANGUAGE_NONE][0]['value'] = $form_state['values']['pass'];
}


UPDATE: OP changed their question to use matching function names. Apparently new $user is saved, but field_magentopass wasn't updated.

Lastly, an alternative approach, based on form_set_value and the #validate handler

/**
 * Implements hook_form_FORM_ID_alter
 * User register form id: user_register_form
 */
function mymodule_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {

  drupal_set_message("Form ID is : " . $form_id);
  $form['#validate'][] = 'mymodule_user_register_validate';

}

function mymodule_user_register_validate($form, &amp;$form_state){
  $form['field_magentopass']['#parents'] = array('field_magentopass'); 
  form_set_value($form['field_magentopass'], array(LANGUAGE_NONE =&gt; array(0 =&gt; array('value' =&gt; $form_state['values']['pass']))), $form_state);
}