1

Below is my form and form submission function. The form is displayed in page-front.tpl.php. Using this code i could print $_POST variable in the front page. But i would like to submit to some other page say page-result.tpl.php. How could i do that without using $_session variables

    function q_search_form($form_state) {

$form['category'] = array(
    '#type' => 'select',
    '#options' => array('' => 'Any', 2 => 'Automotive', 1 => '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['city'] = array(
    '#type' => 'select',
    '#options' => array('' => 'Any', 'kozhikode' => 'Kozhikode', 'kochi' => 'Kochi'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<tr><td width="170">City</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['property'] = array(
    '#type' => 'select',
    '#options' => array('' => 'Any', 18 => 'Land and House', 17 => 'Land'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<tr><td width="170">Property</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['wanto'] = array(
    '#type' => 'select',
    '#options' => array('' => 'Any', 'sell' => 'Sell', 'buy' => 'Buy'),
    '#attributes' => array('class' => 'drop-box'),
    '#prefix' => '<tr><td width="170">Want to</td><td width="300">',
    '#suffix' => '</td></tr>'
);
$form['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;
}


  function q_search_form_submit($form, &$form_state) {
    $wantto = $form_state['values']['wanto'];
    $property = $form_state['values']['property'];
    $city = $form_state['values']['city'];
    $category = $form_state['values']['category'];

    $sql = ' SELECT A.nid FROM node A 
        LEFT JOIN content_type_item B ON A.vid = B.vid
        LEFT JOIN term_node C ON A.vid = C.vid
        LEFT JOIN term_hierarchy D ON D.tid = C.tid
        WHERE A.type = "item" 
        AND B.field_tr_type_value = "'.$wantto.'"
        AND B.field_city_value = "'.$city.'"
        AND D.parent = '.$category.'
        AND C.tid = '.$property.'
      ';
   $result = db_query($sql);   
  while ($row = db_fetch_array($result)) {
     $output['srch_result_nid'][] = $row['nid'];
    }


  $form_state['rebuild'] = TRUE;


  }
1

In your form_submit, add $form_state['redirect'] = <your_url>, at the end.

  • 1
    If i use $form_state['redirect'] $_POST values wont be available in the new url – Nabil May 25 '13 at 6:16
  • you could allocate the value in some other global variable and unset the variable after use. – AjitS May 25 '13 at 6:26
0

This is the multi-step form problem. Try http://drupal.org/project/mforms

You end up with the data stashed into an array on each step.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.