Skip to main content
Removed Drupal 7 from title, added 7 tag.
Link

Drupal 7 Autocomplete URLs

Source Link
cmmsites
  • 119
  • 1
  • 3
  • 6

Drupal 7 Autocomplete URLs

After scouring the www for a solution, I thought I'd post my question here. I've got an autocomplete textfield that's actually retrieving custom URLs from the taxonomy_term_data and field_data_cip_title (custom field for one of my taxonomy vocabularies) tables. Here's the script that I'm using to create the custom URLs:

SELECT CONCAT('<a href=\"/college/disciplines/check?eid=', ttd.tid, '\">', ttd.name, ': ', fdct.cip_title_value, '</a>') cip
  FROM {taxonomy_term_data} ttd,
       {field_data_cip_title} fdct
 WHERE ttd.tid = fdct.entity_id
   AND fdct.entity_type = 'taxonomy_term'
   AND fdct.bundle = 'cipcodes2010'
   AND fdct.deleted = 0
   AND LENGTH(ttd.name) = 7
   AND CONCAT(ttd.name,fdct.cip_title_value) LIKE :string
 LIMIT 0, 7", array(':string' => '%' . $string . '%')

The URLs appear just fine in the autocomplete textfield, and clicking on one of them will take you to the correct URL.

However, when clicking on a link, the HTML of the link appears in the textfield for a brief moment prior to being taken to the URL:

<a href="/college/disciplines/check?eid=5373">01.1202: Soil Chemistry and Physics.</a>

which is quite unattractive. Also, if the user uses the arrow keys to navigate to the desired choice, and then hits the enter key, nothing happens other than the selected HTML appearing in the textfield.

Is there a better way to return clickable - or selectable via arrow keys - autocomplete results that can be acted upon?

Please let me know if I need to elaborate a bit more, and I'd be more than happy to do so.