2011-12-22 3 views
1

D7 폼에 체크 박스를 추가하고 싶습니다. 어떤 이유로 든 아래 스 니펫이 작동하지 않습니다. 어떤 아이디어가 왜 또는 어떤 충고를 적절히하는 방법?Drupal-form에 여러 개의 체크 박스 추가하기

$options = array('A', 'B', 'C'); 
foreach ($themas as $thema) { 

     // Initialize array 
     $ra = array(); 

     // Fill up the array with different keys 
     $key = $prefix.'_thema_'.$thema->tid.'_fiche'; 
     $ra[$key]['#type'] = 'checkboxes'; 
     $ra[$key]['#name'] = $prefix.'_thema_'.$thema->tid.'_opties'; 
     $ra[$key]['#options'] = $options; 
} 

답변

3

나는 당신이 루프의 모든 단계에서 $ra를 다시 초기화하는 것 때문에 그것이 오직 체크 박스 한 세트를 포함 할 것이다 그래서 생각합니다.

$options = array('A', 'B', 'C'); 

// Initialize array 
$ra = array(); 

foreach ($themas as $thema) { 
    // Fill up the array with different keys 
    $key = $prefix.'_thema_'.$thema->tid.'_fiche'; 
    $ra[$key]['#type'] = 'checkboxes'; 
    $ra[$key]['#name'] = $prefix.'_thema_'.$thema->tid.'_opties'; 
    $ra[$key]['#options'] = $options; 
} 

$form['some_key'] = $ra; 

은 또한 당신의 $prefix 문자열이 # 기호로 시작하지 않도록 또는 드루팔은 속성이 아니라 렌더링 할 필요가있는 요소를 고려할 것 : 루프의 외부로 초기화하는보십시오.

+0

사실 참으로 초기화 문제였습니다! '# options' 값은 매번 덮어 쓰기됩니다. 감사 – Michiel

관련 문제