function my_form_menu() {
$items['user/%user/password'] = array(
'title' => '修改密码',
'page callback' => 'drupal_get_form',
'page arguments' => array('change_user_pass',1),
'access callback' => 'user_edit_access',
'access arguments' => array(1),
'weight' => 0,
'type' => MENU_LOCAL_TASK,
);
return $items;
}
function change_user_pass($form, &$form_state, $account) {
$category = 'account';
if (!isset($form_state['user'])) {
$form_state['user'] = $account;
}
else {
$account = $form_state['user'];
}
$form['#user'] = $account;
$form['#user_category'] = $category;
user_account_form($form, $form_state);
$langcode = entity_language('user', $account);
unset($form['account']['current_pass']['#description']);
unset($form['account']['pass']['#description']);
$form['account']['mail']['#access'] = FALSE;
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function change_user_pass_submit($form, &$form_state) {
$account = $form_state['user'];
$edit_user = array(
'pass' => $form_state['values']['pass'],
);
$account_unchanged = clone $account;
user_save($account_unchanged, $edit_user);
$form_state['redirect'] = 'user/'.$form_state['user']->uid.'/password';
drupal_set_message('密码修改成功');
}