hook_search documentation says this: "You will need to merge any custom search values into the search keys using a key:value syntax". But what if I just w
ant a plain old simple form with some input fields and the results in a pager fashion.
Say that the search would be built into a url like this
www.host.com/car/search?name=volvo&lage=20&uage=30&city=london&page=1
Would that be hard to accomplish?
I've tried to look at the search.module and I'm not able to figure out how to build the url like this.
This used to be a really simple task for me.. but in this "framework" I'm lost.
The problem is the forms and how it passes the POST and GET's.. it seems like its doing both sometimes.. redirections?
I really don't know where to fetch the POST values and then the GET's when the first post is done.
This is what I've done so far:
car_menu() {
...
else if (arg(0) == 'car' && arg(1) == 'search') {
$keys = car_search_get_keys();
watchdog('car', 'path: car/search' . $keys);
$items[] = array(
'path' => 'car/search'. $keys,
'title' => 'search cars',
'callback' => 'car_search_view',
'access' => $view_access,
'type' => MENU_CALLBACK);
...
}
/* this one is taken from search.module */
function car_search_view() {
if (!isset($_POST['form_id'])) {
$keys = car_search_get_keys();
if (trim($keys)) {
// car search works...
if (car_do_search()) {
$result = car_get_search();
}
}
// Construct the search form.
$output = drupal_get_form('car_search_view_form', $keys);
$output .= $results;
return $output;
}
return drupal_get_form('car_search_view_form', $keys);
}
function car_search_view_form($query_string = '') {
// query_string is always emtpy here...
$form['#action'] = url('car/search');
$form['search']['name'] = array(
'#title' => t('Name'),
'#type' => 'textfield',
'#default_value' => $query_string, // just a test... query_string is empty
'#size' => 40
);
$form['search']['lage'] = array(
'#title' => t('Lower age'),
'#type' => 'textfield',
'#default_value' => WHAT GOES HERE?,
'#size' => 40
);
$form['search']['uage'] = array(
'#title' => t('Upper age'),
'#type' => 'textfield',
'#default_value' => WHAT GOES HERE?,
'#size' => 40
);
$form['search']['city'] = array(
'#title' => t('City'),
'#type' => 'textfield',
'#default_value' => WHAT GOES HERE?,
'#size' => 40
);
$form['search']['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
'#prefix' => '<div class="action clear-block">',
'#suffix' => '</div>',
);
return $form;
}
/* dont really know where to gather the POST/GET data. */
function car_search_get_keys() {
// Extract keys as remainder of path
// Note: support old GET format of searches for existing links.
$query_string = '';
if($_REQUEST['name']) {
$query_string = '?name=' . $_REQUEST['name'];
}
if($_REQUEST['lage']) {
$query_string = '?lage=' . $_REQUEST['lage'];
}
if($_REQUEST['uage']) {
$query_string = '?uage=' . $_REQUEST['uage'];
}
if($_REQUEST['city']) {
$query_string = '?city=' . $_REQUEST['city'];
}
return $query_string;
}
Any hints or pointers would be much appreciated.