I'm kind of new to drupal (been working with it for 2 months) and i seem to hit a wall with this issue . I've written a little module to allow my users to find phone numbers quickly . It uses autocomplete and works perfectly fine when the user is logged in , but fail when it ain't the case (no icon in the field no http requests fired).
Digging a little further , i can see that neither the autocomplete.js is loading nor the targeted field is properly formatted for autocomplete .
<form action="/" method="post" id="annuchum-form" accept-charset="UTF-8"><div><div class="form-item form-type-textfield form-item-search">
<label for="edit-search">Nom de l'agent </label>
<input type="text" id="edit-search" name="search" value="" size="30" maxlength="128" class="form-text" />
<div class="description">Tapez une recherche et cliquez votre choix pour obtenir le numéro</div>
</div>
Anybody got any idea ? Maybe I missed something as I'm a seasoned php Dev but a total Drupal Newbie .I've searched the whole net looking for a clue
here my .module
<?php
/**
* @file
* Un module pour la récupération de données d'annuaire , et leur présentation sous UI Web 2.0
*/
/**
* Immplements hook_block_help().
* @param $path
* @param $arg
* @return string
*/
function annuchum_help($path,$arg)
{
switch($path)
{
case "admin/help#annuchum":
return '<p>' . t("Annuaire du Centre Hospitalier Universitaire") . '</p>';
break;
}
}
/**
* Implements hook_block_info()
*/
function annuchum_block_info()
{
$blocks['annuchum'] = array(
'info' => t('Annuaire CHUM'),
'cache'=> DRUPAL_CACHE_PER_ROLE,
);
return $blocks;
}
function annuchum_block_view($delta='')
{
switch($delta)
{
case 'annuchum':
$block['subject'] = t('Annuaire CHU ');
$block['content'] = drupal_get_form('annuchum_form');
break;
}
return $block;
}
function annuchum_form()
{
$form =array();
$form['search'] = array(
'#title' => t('Nom de l\'agent'),
'#type' => 'textfield',
'#size' => 30,
'#autocomplete_path' => 'annuchum/autocomplete',
'#description' => 'Tapez une recherche et cliquez votre choix pour obtenir le numéro',
);
$form['annulink'] =array('#markup' => "<a href='http://portail.fr:81/?q=annuaire-interne'>Annuaire détaillé</a>");
return $form;
}
function annuchum_menu()
{
$items['annuchum/autocomplete'] = array(
'page callback' => '_annuchum_autocomplete',
'title' => 'autocomplete pour annuaire',
//'access callback' => TRUE,
//'access' => user_access('access annuchum autocomplete'),
'access arguments' => TRUE,
'type' => MENU_CALLBACK,
'delivery callback' => 'drupal_json_output',
);
return $items;
}
function _annuchum_autocomplete($string ='')
{
$matches = array();
$res = db_query("SELECT node.nid , node.title,field_prenom_value,field_tel_value
FROM field_data_field_tel, field_data_field_prenom, node
WHERE field_data_field_tel.entity_id = node.nid
AND field_data_field_prenom.entity_id = node.nid
AND node.type = 'annuaire'
AND node.title LIKE LOWER(:ustring) ",array(':ustring' => '%' . db_like($string) . '%'));
foreach($res as $node)
if(strlen($node->title) + strlen($node->field_prenom_value) < 15)
$matches[$node->field_tel_value] = check_plain($node->title . " " .$node->field_prenom_value . " " . str_replace(" ","",$node->field_tel_value));
else
$matches[$node->field_tel_value] = check_plain($node->title . " " .substr($node->field_prenom_value, 0 , 12 - strlen($node->title) > 0 ? 12 - strlen($node->title): 1) . ". " . str_replace(" ","",$node->field_tel_value));
//print_r($matches);
//echo 'alive';
//return $matches;
drupal_json_output($matches);
}
?>
Sorry for poor grammar , i'm not a native speaker . Thanks in advance :)