1

I am writing a module and I need to retrieve values set in a form_submit function from a page handler function. The reason is that I am rendering results of a form submit on the same page as the page handler.

I have this working, but I am using global variables, which I don't like. I'd like to be able to use the $form_state['storage'] for this, but can't since I don't have access to the $form_state variable from the page handler.

Any suggestions?

googletorp
  • 33,075
  • 15
  • 67
  • 82
Aaron
  • 3,249
  • 4
  • 35
  • 51

1 Answers1

0

RE: Drupal: How to Render Results of Form on Same Page as Form

You don't have access to $form_state in the page handler, but I think it might be available to your form builder function automatically. See if you can dump it out using something like

function _ncbi_subsites_show_paths_form($form_state) {
  dsm($form_state);
 // everything else
}

Another possibility, though not much better than using globals, would be to use Drupal's variable_set() and variable_get functions.

If you're dealing with just a single value you could pass it to page as a URL argument from a $form['#redirect'] in the submit handler.

Community
  • 1
  • 1
  • Several good ideas. I will try some of them. Surprises me this isn't a common need. My understanding is that you can either: 1) send the user directly to a form from an implementation of hook_menu(), sending drupal_get_form() as a callback and the name of the form building function as the argument. 2) Use pass a page handler from hook_menu and call drupal_get_form from within that function. Isn't that the only way to output other content with the form by concatenating strings to the output of drupal_get_form? Seems to me you'd often want the page handler to communicate with the form. – Aaron May 05 '10 at 13:06
  • What do you need the page handler to do with the form? You can send any number of additional arguments with drupal_get_form(), you just need the first argument to be the form id. –  May 06 '10 at 09:38