0

drupal でフォームを作成しました。提出の仕方がわかりません。フォームから取得した値を使用して、データベースからいくつかの選択を行いたいと考えています。ここにフォームを作成するための私のコードがあります

    function q_search_form() {
$form['qsearch']['category'] = array(
    '#type' => 'select',
    '#options' => array(0 => 'Any', 1 => 'Automotive', 2 => 'Real Estate'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<table width="470"><tr><td width="170">Select Category</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['qsearch']['city'] = array(
    '#type' => 'select',
    '#options' => array(0 => 'Any', 1 => 'Calicut', 2 => 'Kochi'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<tr><td width="170">City</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['qsearch']['property'] = array(
    '#type' => 'select',
    '#options' => array(0 => 'Any', 1 => 'House', 2 => 'Land'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<tr><td width="170">Property</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['qsearch']['wanto'] = array(
    '#type' => 'select',
    '#options' => array(0 => 'Any', 1 => 'Sell', 2 => 'Buy'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<tr><td width="170">Want to</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['qsearch']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Search'),
    '#attributes' => array('id' => 'Search', 'class' => 'srch-button'),
    '#prefix' => '<tr><td><a class="adv-srch" href="#">Advance Search</a></td><td>',
    '#suffix' => '</td></tr></table>'
);
return $form;

}

4

3 に答える 3

0

次の送信関数を記述できます。

function q_search_form_submit($form, &$form_state) {
  // To get selected values from form
  $values = $form_state['values'];
  // do print_r($values); exit; to check the values
}
于 2013-05-24T10:05:24.097 に答える
0

関数内で必要なことはほとんど何でもできますform_submit

function q_search_form_submit($form, &$form_state) {
  $category = $form_state['values']['category'];
  $city = $form_state['values']['city'];
  //etc..

  //use these values to query your database tables
  $query = db_select($category, 'c');
  //narrow results to those only in the selected city:
  $query->join($city, 'cy', 'c.city = cy.cid');
  //narrow results further with more ->join statements
  $results = $query
    ->fields('c', array(fields you want from the categories table))
    //fields from other tables...
    ->execute();

  //do whatever with the $results (print on a different page, print in a table, etc).
于 2013-07-23T18:24:51.167 に答える