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' => '_org_autocomplete',
'access callback' => TRUE,
'type' => 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
->fields('c', array('name'))
->condition('c.name', '%' . db_like($string) . '%', 'LIKE')
->range(0, 10)
->execute();
foreach($return as $row) {
$matches[$row->name] = $row->name;
}
if ($_SERVER['HTTP_REFERER'] == url('user/register', array('absolute' => 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(&$form, &$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