Drupal: Auto complete field
<?php
//$Id$
/**
* @file
*
* An example of Drupal auto complete text field
*
* @author Drupal Developer
*/
/**
* Implementation of hook_menu
*
* @author Drupal Developer
*/
function mymodule_menu() {
$items = array();
$items['myform'] = array(
'title' => 'My auto complete form',
'title callback' => 't',
'page callback' => 'drupal_get_form',
'page arguments' => array('mymodule_form'),
'access arguments'=> array('use my form'),
);
$items['mypath'] = array(
'title' => 'My operation',
'title callback' => 't',
'page callback' => 'my_function',
'access arguments'=> array('use my operation'),
);
return $items;
}
/**
* mymodule_form
*
* Return form with an auto complete text field
*
* @author Drupal Developer
*/
function mymodule_form() {
$form = array();
$form['myautocomplete_field'] = array(
'#type' => 'textfield',
'#title' => t("My Autocomplete field"),
'#autocomplete_path' => 'mypath',
);
$form['myautocomplete_submit'] = array(
'#type' => 'Submit',
'#title' => t("Submit"),
);
return $form;
}
/**
* my_function
*
* Return key=>values matching the text in the textbox
*
* @author Drupal Developer
*/
function my_function() {
//Your code goes here
//This function should return kep=>value as an array
return $myarray();
}
?> (3 votes)
- Login or register to post comments
- 2134 reads
-
Your feedback





Recent comments
8 weeks 4 days ago
27 weeks 1 day ago
28 weeks 6 days ago
38 weeks 2 days ago
42 weeks 4 days ago
43 weeks 5 days ago
43 weeks 5 days ago
43 weeks 5 days ago
43 weeks 5 days ago
44 weeks 1 day ago