2014-02-22 7 views
0

사용자 프로필 편집 페이지로 사용자 정의하고 싶습니다. 편집 경로는 다음과 같습니다 XXX/사용자/2/편집 나의 templage 파일에서 1. 내 사용자 프로파일 form.tpl.php 파일drupal 7 사용자 프로필 템플릿이 변경 사항을 저장할 수 없습니다.

 function MYTHEME_theme() { 
     'user_profile_form' => array(
     'arguments' => array('form' => NULL), 
     'render element' => 'form', 
     'template' => 'user-profile-form', 
     'path' => drupal_get_path('theme', 'bootstrap_subtheme').'/templates', 

), 
} 
function MYTHEME_preprocess_user_profile_form(&$vars) { 
    drupal_set_title('Account settings'); 
    unset($vars['form']['account']['mail']['#description']); 
    $vars['form']['account']['mail']['#title'] = t('Email:'); 
    unset($vars['form']['picture']['#title']); 
    unset($vars['form']['picture']['picture_delete']); 
    $vars['form']['picture']['picture_upload']['#title'] = t('Upload new photo:'); 
    $vars['form']['picture']['picture_upload']['#attributes']['class'][] = 'form-text'; 
    unset($vars['form']['picture']['picture_upload']['#description']); 
    unset($vars['form']['account']['current_pass']['#description']); 
    unset($vars['form']['account']['pass']['#description']); 
    unset($vars['form']['account']['pass2']['#description']); 
    unset($vars['form']['field_birthday']['und']['#prefix']); 
    unset($vars['form']['field_birthday']['und']['#suffix']); 
    unset($vars['form']['field_birthday']['und']['#title']); 
    $vars['form']['account']['pass']['pass1']['#title'] = t('New password:'); 
    $vars['form']['account']['pass']['pass2']['#title'] = t('Re-enter new password:'); 
    $vars['form']['actions']['submit']['#value'] = t('Save changes'); 
    $vars['form']['actions']['submit']['#attributes']['class'][] = 'btn'; 
    $vars['form']['actions']['submit']['#attributes']['class'][] = 'btn-purple'; 
$vars['form']['account']['mail']['#size']=20; 
} 

:

<div class="row-fluid"> 
<div class="span1 offset2">Gender:</div> 
<div class="span4 offset1"><?php print render($form['field_gender']);?></div> 
</div> 
<div class="row-fluid"> 
<div class="span1 offset2">Password:</div> 
<div class="span4 offset1"><?php print render($form['account']['pass']);?></div> 
</div> 
<?php print render($form['actions']);?> 

이제 양식 예상대로 보이지만 암호를 변경할 때 오류는 없지만 새 암호로는 로그인 할 수 없습니다. 나는 그것을 다시 시험해 보았다. 그것은 오직 관리자 만이 그것을 바꿀 수있는 것처럼 보이고, 인증 사용자는 자신의 암호를 변경할 수 없다.

답변

0

이렇게 사용자 지정 사용자 "계정"페이지를 만들었습니다. 내 방식은 귀하의 질문에 정확하게 대답하지는 않지만 이것이 귀하가 찾고있는 것을 성취하는 더 좋은 방법이라고 생각하며 귀하에게 더 많은 유연성을 제공합니다.

내 맞춤 모듈에는 이러한 고리가 있습니다. (모듈을 자신의 모듈 이름으로 대체하십시오).

이렇게하면 기본 사용자 양식 경로가 비활성화됩니다.

function module_admin_paths_alter(&$paths) { 

    $paths['user'] = FALSE; 
    $paths['user/*'] = FALSE; 

} 

function module_menu() { 
    $items = array(); 

    // User account url 
    $items['manage/account'] = array(
    'title' => 'User account', 
    'description' => 'Edit account settings', 
    'page callback' => 'module_edit_account', 
    'access callback' => 'user_is_logged_in', 
    'type' => MENU_NORMAL_ITEM, 
); 

    return $items; 
} 

.. 사용자 정의 사용자가 URL을 관리하는 사용자 양식 및 페이지를 만듭니다. 이 방법은 잘 작동

function module_account_form_submit($form, &$form_state) { 

    global $user; 

    $values = $form_state['values']; 

    // Get user info. Use user global for security reasons and not id from form. 
    $user_account = user_load($user->uid); 

    $user_edit = array(
     'mail' => $values['mail'], 
     'language' => $values['langcode'] 
    ); 

    // If user want to change password.. 
    if (@!empty($values['pass'])) { 
     $user_edit['pass'] = $values['pass']; 
    } 

    // Get default timezone from system 
    $user_account->timezone = date_default_timezone(false);  

    // Save existing user 
    user_save($user_account, $user_edit); 

    drupal_set_message(t('Settings saved')); 
} 
+0

감사 :

function module_edit_account() { drupal_set_title(t('Account')); global $user; $html = render(drupal_get_form('module_edit_account_form', $user)); return $html; } function module_edit_account_form($form, &$form_state, $user_data) { // If no values.. use userdata.. if (@empty($form_state['values'])) { $values = $user_data; } else { $values = $form_state['values']; } $form = array(); // We dont want to deal with hierarchical form values. $form['#tree'] = false; $form['user'] = array( '#type' => 'fieldset', '#title' => t('User information'), '#collapsible' => FALSE, '#collapsed' => FALSE, '#weight' => 2, ); $langs = language_list(); $lang_options = array(); foreach ($langs as $iso => $lang) { $lang_options[$iso] = $lang->name; } $form['user']['firstname'] = array( '#type' => 'textfield', '#title' => t('Firstname'), '#description' => t('Define firstname.'), '#default_value' => (@!empty($values['firstname']) ? $values['firstname'] : ''), '#required' => false, ); $form['user']['lastname'] = array( '#type' => 'textfield', '#title' => t('Lastname'), '#description' => t('Define lastname.'), '#default_value' => (@!empty($values['lastname']) ? $values['lastname'] : ''), '#required' => false, ); $form['user']['pass'] = array( '#type' => 'password_confirm', '#description' => t('If you want to change your current password type new password.'), '#required' => false, ); $form['user']['langcode'] = array( '#type' => 'select', '#title' => t('Language'), '#options' => $lang_options, '#default_value' => (@!empty($values['language']) ? $values['language'] : ''), '#required' => true ); $form['user']['mail'] = array( '#type' => 'textfield', '#title' => t('Email'), '#description' => t('Define email address.'), '#default_value' => (@!empty($values['mail']) ? $values['mail'] : ''), '#required' => true, ); $form['user']['phone'] = array( '#type' => 'textfield', '#title' => t('Phone number'), '#description' => t('Define telephone number.'), '#default_value' => (@!empty($values['phone']) ? $values['phone'] : ''), '#required' => false, ); $form['user']['address'] = array( '#type' => 'textfield', '#title' => t('Address'), '#description' => t('Define address.'), '#default_value' => (@!empty($values['address']) ? $values['address'] : ''), '#required' => false, ); $form['user']['postcode'] = array( '#type' => 'textfield', '#title' => t('Postcode'), '#description' => t('Define postcode.'), '#default_value' => (@!empty($values['postcode']) ? $values['postcode'] : ''), '#required' => false, ); $form['user']['city'] = array( '#type' => 'textfield', '#title' => t('City'), '#description' => t('Define city.'), '#default_value' => (@!empty($values['city']) ? $values['city'] : ''), '#required' => false, ); $form['btn_submit'] = array( '#type' => 'submit', '#attributes' => array('class' => array('button')), '#value' => t('Save changes'), '#submit' => array('module_account_form_submit'), '#validate' => array('module_account_form_validate'), ); return $form; } 

양식 유효성 검사 :

function module_account_form_validate($form, &$form_state) { // Check user email.. if ($error = user_validate_mail($form_state['values']['mail'])) { form_set_error('mail', $error); } } 

양식 .. 제거 버전을 제출이 몇 가지 여분이 예에서 처리되지 않는 필드가 포함되어 있습니다. 그러나 render (drupal_get_form ('module_edit_account_form', $ user)); 작동하지 않습니다. 나는 우리가이 함수에 사용자 객체를 전달할 수 없다고 생각한다. 사용자 개체를 제출 기능으로 옮겼습니다. – user3210341

+0

예, 내 자신의 코드에서 사용자 지정 사용자 데이터를 해당 drupal_get_form 함수에 전달합니다. 그래서 이것은 단지 예입니다 .. – Hardy