We're using the apachesolr_search module on our site. (This is a site I inherited fully coded, so there's tons going on that I'm not intimately familiar with yet.) We have a search block that has been customized (see this post for details; we did eventually get the radio buttons to display, although in a really dirty, non-drupal way.)

I'm trying to get the form values on submit. Forgetting for a moment the radio buttons, I can't even figure out a way to get the value of the search box. Obviously it's getting passed to the solr search, but when I look at the Net panel in Firebug, there are no POST requests, only GET. In my submit function (which does run), I've tried print_r('$_POST'), echo $form_state['values']['search_box'] (where search_box is the element name of the actual form element), tried looping through $form_state and printing all key/value pairs... nothing. Not a single one of these returns anything.

Obviously there's a redirect occurring somewhere that sends the value of the search_box to the solr search module to build the GET request, but I can't for the life of me figure out where it's happening. I think in order to see the values of the posted form, I'd need to intercept the values before the redirect - how do I do that?


Unless I'm mistaken, there is no redirect taking place. Instead the hook_search is used, which will pass the search params from the url.

  • That's the problem, though - what I really need to do is modify the URL, but I can't seem to get the values from the form itself. If I have three form fields, and all of them are filled out, there should be a $_POST somewhere that contains all three field/value pairs. There isn't.
    – EmmyS
    Apr 9 '12 at 18:17
  • No, search forms don't use the POST method. They use GET and hence the variables are in the URL. May 9 '13 at 14:23

The redirect happens in search_form_submit() with this line:

$form_state['redirect'] = 'search/' . $type . '/' . $keys;

You can override it in a hook_form_alter() like so:

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'search_box_form' || $form_id == 'search_block_form' || $form_id == 'search_theme_form') {
    // Alter the form if you need to
    $form['something']['#some-attribute'] = 'something';

    // Add a submit handler if you want to alter the redirect
    $form['#submit'][] = 'MYMODULE_search_form_submit';

function MYMODULE_search_form_submit(&$form, &$form_state) {
    // Redirect to somewhere else if that's what you're after
    $form_state['redirect'] = 'somewhere-else';

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.