Created
December 4, 2012 20:55
-
-
Save kevinchampion/4208563 to your computer and use it in GitHub Desktop.
Drupal 6 Autocomplete example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Autocomplete ajax helper to retrieve autocomplete options from textual mcard | |
* discount search. | |
* | |
* @param $search | |
* User entered search string. | |
* | |
* @return | |
* JSON listing of autocomplete search options. | |
*/ | |
function mcard_search_autocomplete($search = '') { | |
$matches = array('discount 1', 'discount 2', 'discount 3'); | |
watchdog('mcard', 'autocomplete search query: !query !args', array('!query' => '<pre>' . print_r($search, TRUE) . '</pre>', '!args' => '<pre>' . print_r($_GET, TRUE) . '</pre>'), WATCHDOG_NOTICE); | |
/*if ($search) { | |
$result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $search, 0, 10); // only 10 results will show | |
while ($user = db_fetch_object($result)) { | |
$matches[$user->name] = check_plain($user->name); | |
} | |
}*/ | |
drupal_json($matches); //Returns the data in JSON format | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$form['search'] = array( | |
'#type' => 'textfield', | |
'#description' => t('Search for discounts'), | |
'#autocomplete_path' => 'treasury/mcard/discounts/autocomplete', | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment