2009-10-14 5 views
0

편집 :Drupal - 한 페이지에 user_profile_form을 두 개 이상 포함하십시오.

조치가 동일하거나 다른 것으로 생각됩니다.

function mytheme_user_profile_form($form) { 
     global $user; 
     $uid = $user->uid; 
     //print '<pre>'; print_r($form); print '</pre>'; 
    $category = $form['_category']['#value']; 

    switch($category) { 
      case 'account': 
      $form['#action'] = '/user/'.$uid.'/edit?destination=user/'.$uid; 
         break; 
     case 'education': 
         $form['#action'] = '/user/'.$uid.'/edit/education?destination=user/'.$uid; 
         break; 
     case 'experience': 
         $form['#action'] = '/user/'.$uid.'/edit/experience?destination=user/'.$uid; 
         break; 
      case 'publications': 
         $form['#action'] = '/user/'.$uid.'/edit/publications?destination=user/'.$uid; 
         break; 
     case 'conflicts': 
         $form['#action'] = '/user/'.$uid.'/edit/conflicts?destination=user/'.$uid; 
         break; 
    } 

     //print '<pre>'; print_r($form); print '</pre>'; 
     //print $form['#action']; 
     $output .= drupal_render($form); 
     return $output; 
} 

그러나 양식을 실제로 렌더링 할 때 양식 동작은 변경되지 않았습니다. 그들은 모두/user/% uid입니다.

양식 작업을 수정할 수 있습니까?

사용자 프로필 양식의 여러 가지 "범주"를 한 페이지에 포함하고 있으며 코드에서 내가 지정한 양식을 올바르게 출력합니다. 각 양식은 별도의 접을 수있는 div에 있습니다.

내 문제는 두 가지입니다.

(1) 필드에 대한 기존의 값이 미리 채워지지하고

(2) 경고가 발생합니다 하나 개의 섹션에 대해 "저장"을 클릭 : 이메일 필드에 관계없이 어떤 형태의, 필요 실제로 저장하는 중입니다.

문제 번호 2의 경우 버튼의 이름이 모든 경우에 동일하고 양식 ID가 동일하기 때문에 문제가 확실합니다.

print '<h3>&ndash; Account Settings</h3>'; 
print '<div class="expand">'; 
print(drupal_get_form('user_profile_form', $user, 'account')); 
print '</div>'; 

print '<h3>&ndash; My Info</h3>'; 
print '<div class="expand">'; 
print(drupal_get_form('user_profile_form', $user, 'Personal')); 
print '</div>'; 

print '<h3>&ndash; Experience</h3>'; 
print '<div class="expand">'; 
print(drupal_get_form('user_profile_form', $user, 'experience')); 
print '</div>'; 

print '<h3>&ndash; Education</h3>'; 
print '<div class="expand">'; 
print(drupal_get_form('user_profile_form', $user, 'education')); 
print '</div>'; 
+0

원본 양식을보고이 양식이 실제로 고유한지 확인해 봤습니까? – mikewaters

답변

1

문제 # 1 :? html 소스를 게시 할 수 있습니까? 문제 # 2의 : OK, 내가 여기에 코드를 단계별로 수 있습니다 : 사용자 프로필 양식 (user_profile_form_validate())에 대한 검증 핸들러가

<?php 
/** 
* Invokes hook_user() in every module. 
* 
* We cannot use module_invoke() for this, because the arguments need to 
* be passed by reference. 
*/ 
function user_module_invoke($type, &$array, &$user, $category = NULL) { 
    foreach (module_list() as $module) { 
    $function = $module .'_user'; 
    if (function_exists($function)) { 
     $function($type, $array, $user, $category); 
    } 
    } 
} 
?> 

같은 모습

user_module_invoke('validate', $form_state['values'], $form_state['values']['_account'], $form_state['values']['_category']); 

를 호출 , 이 양식의 유효성 확인 처리기는 사용자 후크 기능을 찾고 $type = 'validate'으로 호출하는 모든 모듈을 통과합니다. ('카테고리'PARAM 여기에 선택 사항입니다 -의 contrib 모듈을 사용할 필요가 없습니다)

이의이 어떻게되는지 예를 들어 user.module의 사용자 훅을 살펴 보자 :

function user_user($type, &$edit, &$account, $category = NULL) { 
    if ($type == 'view') { 
    $account->content['user_picture'] = array(
     '#value' => theme('user_picture', $account), 
     '#weight' => -10, 
    ); 
    if (!isset($account->content['summary'])) { 
     $account->content['summary'] = array(); 
    } 
    $account->content['summary'] += array(
     '#type' => 'user_profile_category', 
     '#attributes' => array('class' => 'user-member'), 
     '#weight' => 5, 
     '#title' => t('History'), 
    ); 
    $account->content['summary']['member_for'] = array(
     '#type' => 'user_profile_item', 
     '#title' => t('Member for'), 
     '#value' => format_interval(time() - $account->created), 
    ); 
    } 
    if ($type == 'form' && $category == 'account') { 
    $form_state = array(); 
    return user_edit_form($form_state, (isset($account->uid) ? $account->uid : FALSE), $edit); 
    } 
//<-- LOOK HERE --> 
    if ($type == 'validate' && $category == 'account') { 
    return _user_edit_validate((isset($account->uid) ? $account->uid : FALSE), $edit); 
    } 

    if ($type == 'submit' && $category == 'account') { 
    return _user_edit_submit((isset($account->uid) ? $account->uid : FALSE), $edit); 
    } 

    if ($type == 'categories') { 
    return array(array('name' => 'account', 'title' => t('Account settings'), 'weight' => 1)); 
    } 
} 

을 그래서, 그것을 단지 카테고리 == '계정'기능 _use_edit_validate에서

경우의 유효성을 검사하도록되어, 우리가 찾을 :

// Validate the e-mail address: 
    if ($error = user_validate_mail($edit['mail'])) { 
    form_set_error('mail', $error); 
    } 

당신의 오류 메시지가있다.

해당 양식은 카테고리 == '계정'일 때만 유효하므로 카테고리에 상관없이 항상 유효성 검사를하는 것으로 보이는 문제 (# 2)는 양식이 고유 양식으로 렌더링되지 않을 수 있습니다 인스턴스? 드루팔 (Drupal은 매번 완벽한 양식을 렌더링 할 수 있으며 범주가 무엇이든 숨겨진 양식 값을 설정하기 만합니다 (user_pages.inc의 양식 정의 함수에서와 같이)

실제 HTML 소스 출력 .

가 == 업데이트 질문 ===

확인에 응답하여 편집 10-15-09, 그것은 당신의 방법이 가능하지 않을 수 있습니다 (수동 테마 층에 $form['#action'] 편집)처럼 보인다 (참조 this 게시물을 참조). 양식 작업을 변경하려면 hook_form_alter()을 구현하는 사용자 정의 모듈을 작성해야합니다 (테마 템플리트 파일에서는 작동하지 않음). 이 함수를 사용하면 양식이 렌더링되는 방식 (사용자 수정 양식)을 수정할 수 있습니다. 양식 수정에 대한 자세한 내용은 here입니다.

저는 100 % 확신하지는 않습니다. (이미 모듈을 만들어야하는 것처럼 보이기 때문에) 아마 hook_user()에 연결하고 싶을 것입니다. 이 기능은 "... 사용자 계정에서 작업이 수행 될 때 모듈이 반응하도록 허용합니다." 이 기능에서 범주에 반응하고 원하는 사용자 변경을 차단하거나 허용 할 수 있습니다.

그러나 문제가되는 이메일 주소 확인 만하고 기존 사용자를 상대하는 경우 저장하기 전에 이메일 주소가 설정되어 있는지 확인하십시오.

+0

그래, 그게 문제 야. 이걸 조금 더 자세히 설명하기 위해 내 원래 게시물을 편집 중입니다 ... – n00b0101

관련 문제