Hi,
I'm having some problem with AJAX form_autocomplete functionality from the CVS build.
When I navigate to my page with the form_autocomplete it works fine! But when I navigate to another page and again to the one with the form_automplete it doen't work anymore... The form_autocomplete field keeps loading and loading. Looks like a infinitive loop.
I've put in the code I'm using.
The form_autocomplete functionality is great but it doesn't look stable. Any help welcome.
Regards,
Marcel
<?php
// $Id$
/**
* Implementation of hook_help().
*/
function email_help($section='') {
$output = '';
switch ($section) {
case 'admin/modules#description':
$output = t('Allows messages to be send between users.');
break;
}
return $output;
} // function email_help
/**
* Implementation of hook_perm().
*/
function email_perm() {
return array('read messages', 'send messages');
} // function email_perm
/**
* Implementation of hook_menu().
*/
function email_menu($may_cache) {
global $user;
$read_messages = user_access('read messages' );
$send_messages = user_access('send messages' );
$items = array();
if ($may_cache) {
$items[] = array('path' => 'email/recipient_autocomplete',
'title' => t('email recipient autocomplete'),
'callback' => '_email_recipient_autocomplete',
'access' => $send_messages,
'type' => MENU_CALLBACK);
}
else {
$items[] = array('path' => 'email',
'title' => t('email') . ' (' . (int)_email_get_unread_messages() . ')',
'callback' => '_email_inbox',
'access' => $read_messages || $send_messages,
'type' => MENU_NORMAL_ITEM);
$items[] = array('path' => 'email/compose_message',
'title' => t('compose message'),
'callback' => '_email_compose_message',
'access' => $send_messages,
'type' => MENU_NORMAL_ITEM,
'weight' => 1);
$items[] = array('path' => 'email/inbox',
'title' => t('inbox'),
'callback' => '_email_inbox',
'access' => $read_messages,
'type' => MENU_NORMAL_ITEM,
'weight' => 2);
}
return $items;
} // function email_menu
/**
* Helper function for autocompletion
*/
function _email_recipient_autocomplete($string) {
$matches = array();
$sql = 'SELECT name ' .
'FROM {users} ' .
'WHERE LOWER(name) LIKE LOWER("%%%s%%") ' .
'AND status = 1';
$result = db_query_range($sql, $string, 0, 10);
while ($user = db_fetch_object($result)) {
$matches[$user->name] = check_plain($user->name);
}
print drupal_implode_autocomplete($matches);
exit();
} // _email_user_autocomplete
function _email_get_unread_messages($uid = 0) {
// return 3 while not implemented.
return 3;
} // function _email_get_unread_messages
function _email_compose_message() {
$output .= '
Compose Message