0

I'm creating module to use similiar words to get better search result. I have API which will returns top X similiar words for entered word. What I want to achieve is this workflow:

  1. User enter some word into the search form and submit the form

  2. My module call the API, gets the similiar words and change the search query

--- That is what I have done. But next part is problem ---

  1. After sucesful search, alter the form to show user the similiar words I used to change the query.

At the start I expected, that I can save similiar words in hook_search_api_solr_query_alter and then in hook_form_alter change the form to show the words. But after some research I find out that is not possible, because hooks are called in different order.

Is there any way how I can alter form after submit (or validation)?

I also tried to set form_state['rebuild'] in validation hook, but when the form is rebuild, the entered values are erased.

0

hook_form_alter is probably a good approach for displaying the search words in the form.

Assuming you're not submitting the form via AJAX, you need a way of passing the search words to the next page load. One way might be to redirect to the same URL but adding your search words as URL query parameters. You could do that by setting $form_state['redirect'] or calling drupal_goto in your submit function.

Another way, maybe easier, would be to save your search words in the user's session and reading them back in the subsequent page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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