I have a organization text field on the user profile. I wrote a module that uses dbpedia's lookup services to generate an autocomplete list on the field. The code works on my local instance using XAMPP. I installed the module on the server but it doesn't show the autocomplete list. It however recognizes the field as autocomplete by showing me a circle on the field

The code for the autocompelte is

 * Implementation of hook_menu()
function org_ac_menu() {
  $items = array();
  $items['org_ac/autocomplete'] = array(
    'page callback' => 'org_ac_autocomplete',
    'access callback' => TRUE,
    'access arguments' => array('access dbpedia autocomplete'),
    'type' => MENU_CALLBACK,
  return $items;

 * Implementation of hook_form_alter()
function org_ac_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'user_profile_form') {
    $form['field_organization']['und'][0]['value']['#autocomplete_path'] = 'org_ac/autocomplete';

 * Check for possibilities in dbpedia
function org_ac_autocomplete($string = '') {
  $found = array();

  $url = 'http://lookup.dbpedia.org/api/search.asmx/PrefixSearch?QueryString='.urlencode($string).'&MaxHits=5';
  $result = file_get_contents($url);
  $data = simplexml_load_string($result);

  foreach($data->Result as $res_temp)
      $found[check_plain($res_temp->Label)] = check_plain($res_temp->Label);

  • Have you checked that the request is actually going to the server? Using Firebug or the Chrome dev tools look for any javascript errors and view the request/response over the network. – Alfred Armstrong Mar 13 '13 at 14:19
  • I checked that with firebug, the request does go through but the response is just null. Is the server blocking it ? – Jayaram Mar 13 '13 at 14:59
  • A null response suggests an execution error so I'd examine logs next. One thing I notice from your code is you aren't checking what's returned for errors. If the dbpedia site is down or the page returns invalid xml when you reach that foreach loop there'll be a PHP error. – Alfred Armstrong Mar 13 '13 at 15:13
  • Yes thats the next thing I'm going to do but i thought i would try to check if this is working on the server. I finally found the error in the log messages - its because URL file-access is disabled in the server configuration Thanks very much. – Jayaram Mar 13 '13 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.