<?php
/**
* Impelements hook_permission()
*/
function example_permission() {
return array(
'example' => array(
'title' => t('example'),
'description' => t('example text.'),
),
);
}
/**
* Implements hook_menu().
*
* */
function example_menu(){
$items['example/autocomplete'] = array(
'title' => '',
'page callback' => 'drupal_get_form',
'page arguments' => array('example_autocomplete'),
'access arguments' => array('example'),
'type' => MENU_CALLBACK,
);
$items['pincode/autocomplete'] = array(
'page callback' => 'pincode_autocomplete',
'access arguments' => array('example'),
'type' => MENU_CALLBACK
);
return $items;
}
/**
* Implements auto complete call back.
*
* */
function pincode_autocomplete($string){
$matches = array();
$query = db_select("web_pincode","wcm");
$query->fields('wcm',array('pin_code'));
$query->condition('wcm.pin_code', db_like($string) . '%', 'LIKE');
$query->range(0,15);
$res = $query->execute();
while ($res1 = $res->fetchAssoc()) {
$matches[$res1['pin_code']] = check_plain($res1['pin_code']);
}
drupal_json_output($matches);
}
/**
* Implements auto complete form().
*
* */
function example_autocomplete($form, &$form_state){