• Avail guidance to develop Drupal modules & Drupal themes
  • Share and get review of your code
  • Get Access to free CodeBooks and ThemeBooks
  • Drupal 5, 6 and 7 covered

Drupal: Auto complete field

Printer-friendly versionSend to a DeveloperPDF version

<?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();
}
?>

5
Your rating: None Average: 5 (3 votes)
Syndicate content

Recent comments