Hook form:
function location_form(&$form_state, $unused, $form_values) {
$form = array();$form['state'] = array(
'#type' => 'textfield',
'#title' => 'Province',
'#description' => 'Province',
'#autocomplete_path' => 'admin/autocomplete/provinces',
);$form['city'] = array (
'#type' => 'textfield',
'#title' => 'Cidade',
'#description' => 'Cidade',
'#autocomplete_path' => 'admin/autocomplete/cities'
);$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);return $form;
}Hook menu:
function location_menu() { $items['admin/autocomplete/provinces'] = array (
'title' => 'Provinces autocomplete',
'description' => 'Provinces autocomplete',
'page callback' => 'location_provinces_autocomplete',
'access arguments' => array('access administration pages'),
'type' => MENU_CALLBACK,
);$items['admin/autocomplete/cities'] = array(
'title' => 'Cities autocomplete',
'description' => 'Cities autocomplete',
'page callback' => 'location_cities_autocomplete',
'access arguments' => array('access administration pages'),
'type' => MENU_CALLBACK,
);return $items; }
Autocomplete functions:
function location_provinces_autocomplete($input) {
$items = array();$query = "SELECT name FROM location WHERE name LIKE '%s%%' AND level = 1";
$result = db_query($query, $input);
while ($row = db_fetch_object($result)) {
$items[$row->name] = $row->name;
}print drupal_to_js($items);
exit;
}function location_cities_autocomplete($input) {
$items = array();$query = "SELECT name FROM location WHERE name LIKE '%s%%' AND level = 2";
$result = db_query($query, $input);
while ($row = db_fetch_object($result)) {
$items[$row->name] = $row->name;
}print drupal_to_js($items);
exit;
}
Hook form:
function location_form(&$form_state, $unused, $form_values) {
$form = array();
$form['state'] = array(
'#type' => 'textfield',
'#title' => 'Province',
'#description' => 'Province',
'#autocomplete_path' => 'admin/autocomplete/provinces',
);
$form['city'] = array (
'#type' => 'textfield',
'#title' => 'Cidade',
'#description' => 'Cidade',
'#autocomplete_path' => 'admin/autocomplete/cities'
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
}
Hook menu:
function location_menu() {
$items['admin/autocomplete/provinces'] = array (
'title' => 'Provinces autocomplete',
'description' => 'Provinces autocomplete',
'page callback' => 'location_provinces_autocomplete',
'access arguments' => array('access administration pages'),
'type' => MENU_CALLBACK,
);
$items['admin/autocomplete/cities'] = array(
'title' => 'Cities autocomplete',
'description' => 'Cities autocomplete',
'page callback' => 'location_cities_autocomplete',
'access arguments' => array('access administration pages'),
'type' => MENU_CALLBACK,
);
return $items;
}
Autocomplete functions:
function location_provinces_autocomplete($input) {
$items = array();
$query = "SELECT name FROM location WHERE name LIKE '%s%%' AND level = 1";
$result = db_query($query, $input);
while ($row = db_fetch_object($result)) {
$items[$row->name] = $row->name;
}
print drupal_to_js($items);
exit;
}
function location_cities_autocomplete($input) {
$items = array();
$query = "SELECT name FROM location WHERE name LIKE '%s%%' AND level = 2";
$result = db_query($query, $input);
while ($row = db_fetch_object($result)) {
$items[$row->name] = $row->name;
}
print drupal_to_js($items);
exit;
}