Autocomplete on a custom field on the registration form no longer working thanks for reading.

I have a database table containing organisation names. When a user registers on the website, they use a text field I added, which autocompletes with existing organisation names, as a way of attaching them to existing organisations. This used to work fine, but doesn't seem to now, presumably after one of the updates. Now it simply doesn't load anything when typing in, though the little circle appears to indicate that it is connected.

Here's the code:

$items['org/autocomplete'] = array(
  'page callback' =&gt; '_org_autocomplete',
  'access callback' =&gt; TRUE,
  'type' =&gt; MENU_CALLBACK
);


...and...

function _org_autocomplete($string = '') {
  $matches = array();
  $query = db_select('org_orgs', 'c'); // I've checked that the table exists, contains data, and is of this name - that's fine
  $return = $query
    -&gt;fields('c', array('name'))
    -&gt;condition('c.name', '%' . db_like($string) . '%', 'LIKE')
    -&gt;range(0, 10)
    -&gt;execute();

  foreach($return as $row) {
    $matches[$row-&gt;name] = $row-&gt;name;
  }
  if ($_SERVER['HTTP_REFERER'] == url('user/register', array('absolute' =&gt; TRUE))){
    drupal_json_output($matches);

    // The if statement surrounding this line prevents users
    // from viewing the full list by going directly to the
    // /org/autocomplete URL. In removing the if statement, I can
    // test to see if it works at the URL, and it does just fine

  }
}


I've checked that the table exists, contains data, and is of this name - that's fine. The if statement surrounding the drupal_json_output() line prevents users from viewing the full list by going directly to the URL. In removing the if statement, I can test to see if it works at the URL, and it does just fine.

function org_form_user_register_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  $form['field_organisation']['und'][0]['value']['#autocomplete_path'] = 'org/autocomplete';
  // Though no results appear, the 'org/autocomplete' path
  // is confirmed as the correct path because changing it to
  // anything else removes the little autocomplete circle.
  $form['field_organisation']['und'][0]['value']['#description'] = 'If your organisation appears in the above predefined dropdown menu, please select it.';
  $form['#validate'][] = 'org_form_validate';
  $form['#submit'][] = 'org_form_submit';
}


Though no results appear, the 'org/autocomplete' path is confirmed as the correct path because changing it to anything else removes the little autocomplete circle.

Do you have any ideas of what's gone wrong, or if not, what I can do to investigate?

Additionally, in searching for the solution, I found this drupal update: http://drupal.org/node/1901518 Could this be the cause? And if so, what can I do to correct it?

Thanks
What you say suggests it's this line that's the issue:

 if ($_SERVER['HTTP_REFERER'] == url('user/register', array('absolute' =&gt; TRUE))){


so there's presumably some difference between the referrer URL and the one generated by the url() function. You might add lines above it to record the two values using watchdog: that would confirm you are reaching that point in the code and help diagnose the issue.