I have made a module in Drupal 6 that builds a page that shows some data taken from an external database. I want to add a form that let the user filter the data (for example, limit the data output to a specific city instead all the cities). How can I get the value of the submitted form and use it as a filter condition on the page rendering function? The $form_state variable doe not exist when running the page function and I have no way to load the value.

2 Answers 2


It sounds like your problem is about passing the selected value to your page rendering function, upon form submission. There are a few different ways to pass that value from within the form_submit function, including via a URL argument, or setting a cookie, or using some javascript to post the value - or even using variable_set() in the right circumstances. There might be easier better ways than those, and I'd like to know what they are if they exist.

Here's a way to do it via a URL argument:

  1. In the form_submit() function, pass the select data to the page rendering function via drupal_goto(). Eg: drupal_goto( 'this/page/' . $form_state['values']['city']

  2. Be sure that your page rendering function can accept the right argument. in your hook_menu:
    'page arguments' => array( 2 ),
    (or you can just grab the argument using arg( 2 ) from within the page rendering function)

I'm not saying this is necessarily the best way to get the job done, but this should work.

  • You made my day!
    – Terix
    Commented Jun 11, 2012 at 14:50

You could make the external database table visible to Views by using hook_views_data(). Rather than add in a form, you could then leverage the power of Views and have exposed filters.

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.