2010-01-10 8 views
0

필드 연결, 기본값 설정 및 숨김 문제로 작업하고 있습니다. 문제는 기본값을 사용하지만 값의 첫 번째 문자 만 데이터베이스에 제출한다는 것입니다.Drupal 6 : 숨겨진 필드 작업

//Here is how I'm doing it 
$form['field_sr_account'] = array('#type' => 'hidden', '#value' => '45'); 

내 배열을 구성하는 방식에 문제가 있다고 생각되지만 그걸 얻을 수는 없습니다. 나는 누군가가 내가이에 숨겨진 속성을 추가 할 수있는 방법

//Here is the format of the solution to the post - but it's not hidden 
$form['field_sr_account'][0]['#default_value']['value'] = '45'; 

를 제출하고 첫 번째 문자에 대한 해결책을 찾은 후, http://drupal.org/node/59660을 발견?

답변

1

실제로 대답은 값과 숨겨진 특성을 별도로 설정 한 다음 제출자 처리기에서 다음 형식을 사용하여 다시 값을 설정하는 것이 었습니다.

내가 필요한 모든 있는지 모르겠어요 ... 난 아마 변경 형태로 할당 할 필요가 없습니다 가정,하지만 작동하므로 혼자두고 갈거야

$form['#field_sr_account'] = $club; 
    $form['field_sr_account'] = array('#type' => 'hidden','#value' => $club); 
    } 
} 

/*in submit handler, restore the value in the proper format*/ 
$form_state['values']['field_sr_account'] = array('0' => array('value' => $form['#field_sr_account'])); 
1

내가 모두 사용했습니다 http://drupal.org/node/257431#comment-2057358

CCK 숨겨진 필드

/** 
* Implementation of hook_form_alter(). 
*/ 
function YourModuleName_form_alter(&$form, $form_state, $form_id) { 
    if (isset($form['type']) && isset($form['#node'])) { 
    ### Make a CCK field becoming a hidden type field. 
    // ### Use this check to match node edit form for a particular content type. 
    if ($form_id === 'YourContentTypeName_node_form') { 
     $form['#after_build'] = array('_test_set_cck_field_to_hidden'); 
    } 
    } 
} 

function _test_set_cck_field_to_hidden($form, &$form_state) { 
    $form['field_NameToBeHidden'][0]['value']['#type'] = 'hidden'; 
    $form['field_NameToBeHidden'][0]['#value']['value'] = 'testValue'; 

    return $form; 
}