I am trying to provide a form with a single autocomplete text field on the front page. The user can search for a title of the product (commerce_product), and when they submit, they're redirected to a views page with the title as context.

These are baseball cards from multiple sellers, so there can be many cards and variations of a single card with the same name, e.g. multiple sellers sell a "Barry Bonds" card.

When the user enters the name of the card and submits, I need to redirect them to a views page to display all the cards for that particular title (card name).

The part I'm trying to figure out is how to use the selected title on the front page and send the user to a views page with that title so I can use it in a view. I assume that would be a Context, but I'm not having success finding how to do that. To clarify the flow:

  1. User hits front page and searches for a product title.

  2. The user submits and is redirected to a views page.

  3. On the views page, the user can browse all the cards under that title.

  • 1
    Isn't what you're after already what Views do? You enter a keyword into the autocomplete field of the Exposed Filter for the Title field, and you get a list of results, nodes that satisfy the criteria. What is it about that that doesn't suit you? BTW it seems your structure might be improved if you created a Taxonomy Vocabulary for all the Players and let sellers select from an existing list instead of relying on them to enter the name into the Title field. You can even use Autotitle or similar to automatically create Titles out of entered info, and use Taxonomy terms for contextual filtering.
    – prkos
    Aug 13, 2019 at 14:44
  • I don't want the view results on the first page. There's other supplemental content on the first page. The View page is dedicated to search results. Regarding Taxonomy, I don't think it's feasible to create a taxonomy entry for potentially every baseball player who's ever lived.
    – vintorg
    Aug 13, 2019 at 16:23
  • 1
    You can use the Input required (Only display results after the user has selected a filter option.) it's under the Exposed form style setting. Or you can use the Exposed form in block if your Views is a Page Display, so you only show the Filters block of that View somewhere on your site, and when the user uses it, they get redirected to the Views page.
    – prkos
    Aug 13, 2019 at 16:46
  • 1
    Many websites have very long taxonomy lists and Drupal is able to handle them. There are lists/databases in various formats of various things, that can be imported into Drupal. Baseball db might not be free, but maybe you don't need all? You could let users create the Taxonomy entries too, you already allow them to fill in the Titles correctly, using a different structure in the back-end might help handling the site building, while keeping the same user experience.
    – prkos
    Aug 13, 2019 at 16:48
  • @prkos I don't doubt Drupal can handle it, but that's just not feasible. I have a DB source (custom autocomplete) the user pulls from when they add a new product for sale. I'm thinking I'll select back the player name to get the ID, then on the submit I'll redirect to the view page with the context in the URL. I'm thinking that's the way to do it so far. Also, there's no view on the front page. The user would be directed to the view page after entering the player name.
    – vintorg
    Aug 13, 2019 at 16:54

1 Answer 1


Here's how I solved my problem:

  1. Added an ID field (the ID from the source I'm pulling/validating player names) to my variation. On creation of a variation, I store the ID in the field when the user selects the player name during product creation, e.g. "Barry Bonds" is ID 35456 in my source.

  2. I'm using a regular autocomplete route in my form instead of an entity_autocomplete. My autocomplete handler does an entity query on cards (product variations) that are active and match the player name.

  3. After the player is selected from the autocomplete, on form validation, I re-select the player to get the ID.

  4. On form submit I pass the ID with the URL to my views page as a contextual filter, where it expects it as a field value in the URL, e.g. "/player-card-search/35456".

Creating the new ID field in my product variation feels redundant, but it got me to the solution.

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.