2010-07-30 4 views
0

이 필터는 맞춤 필터링 검색을 만들기 위해 노력하고있는 모듈입니다. 하지만 나는 폼 타입 체크 박스의 값을 얻는 것에 대해서는 모른다. 당신이 제출 처리기에서 다음 양식 빌더에 $form['name']['filter']['node_options']에 포함 된 양식 필드의 값을 얻으려고 노력하는 경우양식 API 확인란에서 값 가져 오기

<?php 

function my_module_menu() { 
    $items = array(); 
    $items['my_module/form'] = array(
    'title' => t('My form'), 
    'page callback' => 'my_module_form', 
    'access arguments' => array('access content'), 
    'description' => t('My form'), 
    'type' => MENU_CALLBACK, 
); 
    return $items; 
} 

function my_module_form() { 
    return drupal_get_form('my_module_my_form'); 
} 

function my_module_my_form($form_state) { 
    $form['name'] = array(
    '#type' => 'fieldset', 
    '#title' => t('Search'), 
    '#collapsible' => TRUE, 
    '#collapsed' => FALSE, 
); 

    // Removes the #required property and 
    // uses the validation function instead. 
    $form['name']['first'] = array(
    '#type' => 'textfield', 
    '#title' => t('Search'), 
    '#default_value' => "Keyword", 
    '#description' => "Please enter your keyword.", 
    '#size' => 20, 
    '#maxlength' => 20, 
); 
$form['name']['filter'] = array(
    '#type' => 'fieldset', 
    '#title' => t('Filter'), 
    '#collapsible' => TRUE, 
    '#collapsed' => TRUE, 
); 
    $form['name']['filter']['node_options'] = array(
    '#type' => 'checkboxes', 
    '#title' => t('Default options'), 
    '#default_value' => variable_get('node_options', 0), 
    '#options' => array(
    '31' => t('Chinese'), 
    '28' => t('South Indian'), 
    '18' => t('Pizza'), 

    ), 
    '#description' => t('Filter the results.'), 
); 

    $form['name']['submit'] = array(
    '#type' => 'submit', 
    '#value' => 'Submit', 
); 
    // Adds a new button to clear the form. The #validate property 
    // directs the form to use a new validation handler function in place 
    // of the default. 
/* $form['clear'] = array(
    '#type' => 'submit', 
    '#value' => 'Reset form', 
    '#validate' => array('my_module_my_form_clear'), 
);*/ 

    return $form; 
} 

// This is the new validation handler for our Reset button. Setting 
// the $form_state['rebuild'] value to TRUE, clears the form and also 
// skips the submit handler. 
function my_module_my_form_clear($form, &$form_state) { 
    $form_state['rebuild'] = TRUE; 
} 


//block 
function my_module_block($op = 'list', $delta = 0, $edit = array()) { 
    $block = array(); 

    switch ($op) { 
    case 'list': 
     $block[0]['info'] = t('Custom search form'); 
     break; 
    case 'view': 
     switch ($delta) { 
     case 0: 
      $block['subject'] = t('Custom search'); 
      $block['content'] = drupal_get_form('my_module_my_form'); 
      break; 
     } 
     break; 
    } 

    return $block; 
} 










function my_module_my_form_submit($form, &$form_state) { 
    $redirect_url = 'search/node/'; 
    $redirect_url .= ' category:' . $form_state['values']['filters']; 
    $redirect_url .= ' %' . $form_state['values']['first'] . '%'; 

    $form_state['redirect'] = $redirect_url; 

} 

답변

2

당신은 $form_state['values']['node_options']를 사용해야합니다.

또한 메뉴 콜을 가장 먼저, 두 번째 전화 형태 빌더를 정의하는 두 개의 함수를 정의 할 필요는 없다

$items = array(); 
$items['my_module/form'] = array(
    'title' => t('My form'), 
    'page callback' => 'drupal_get_form', 
    'page arguments' => array('my_module_form'), 
    'access arguments' => array('access content'), 
    'description' => t('My form'), 
    'type' => MENU_CALLBACK, 
); 

로 변경되어야한다.