I have a form which uses a textfield with a custom autocomplete path and it works just as it should. However, I get some unexpected behavior when the title/search string contains a backslash (e.g. '10/07/2016 Meeting').

After some investigation I realized that Drupal seems to interpret those as 4 separate parameters with only the first (in this case 10) being passed to the autocomplete function. I'm not sure how I can prevent this behaviour as the passing of the string to the form is handled internally by Drupal via the '#autocomplete_path' on the textfield itself.

I checked how entity reference handled this, but it is using an entirely custom field and not the '#autocomplete_path' on a regular textfield and wasn't of much use to me.

However it would seem odd to me that the textfield autocomplete shouldn't be able to support search strings with slashes - I just can't find out how to hook into the Drupal form to encode the string somehow.

How can I make my autocomplete field compatible with slashes?

1 Answer 1


Take a cue from the Drupal core's taxonomy autocomplete implementation and just recombine the arguments passed into callback function back into one string:

function taxonomy_autocomplete($field_name = '', $tags_typed = '') {

  // If the request has a '/' in the search text, then the menu system will have
  // split it into multiple arguments, recover the intended $tags_typed.
  $args = func_get_args();
  // Shift off the $field_name argument.
  $tags_typed = implode('/', $args);
  • Seems I was too fixed on checking modules like entity reference that I forgot looking at taxomomy. func_get_args() totally did the trick. Thanks!
    – Zuzuesque
    Commented Jul 9, 2016 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.