I have been working on this all day, and finally have something working - but I feel there must be a better way. I have a page that shows a list of node titles, and a small form on that page of taxonomy select drop downs to filter the nodes by (basically).
If a typical page callback has other dynamic content, and then also shows a form by use of drupal_get_form - what's the best way to get data back to that page callback function?
All the form examples are using drupal_get_form as the page callback function. And those that use form_submit are just setting a drupal message, but what if you need to use that posted form data on a larger page? The only way I could finally figure out was to use variable_set() and variable_get(). But is there a way to send data to the page without writing to the db?
Comments
Comment #2
rfaySure -
A page is just a render array.
$page[] = drupal_get_form(my_form).
...
return $page;
Comment #3
wheelercreek commentedI'm not really sure how that helps me.. here's more info about the module I've written:
How can I do this without storing to the db? I've even tried accessing the $_POST directly, but somewhere in the process it's getting blown away or overwritten...
Comment #4
rfaySorry, it's not clear to me what you want to do.
You're almost doing the page callback right, but in D7 you would leave the page as a render array and let it be themed later. You could set #theme on it. See the render_example.
And sorry, this isn't a support venue. You'll need to spread out and get support in IRC, on drupal.stackexchange, or wherever.
Comment #5
dave reidComment #6
wheelercreek commentedWell - I'm just looking for help understanding how the passing of data is supposed to work with forms-to-pages.. maybe this isn't the right place...
The page callback is working fine, my form appears on the page along with the list of content. When I submit the form, the submit function runs, great - but how do I get data from that submit function back to to the page callback function to use it to filter my query.. without having to first store it in the db?
There doesn't seem to be a way to use form posted data on the page. All the form examples basically just print a message.
Comment #7
rfayTake a look at the core search module and several other places this is done.
What they do is turn the form submission arguments into a new GET, and then build the page based on the GET.
So if your form contains $form_state['status']['state'] = 'co'
then in your submit handler, $form_state['redirect'] = 'my_page/co'
And then that uses the arg to build the page.
Comment #8
wheelercreek commentedperfect, thanks.. that thought hit me this morning too - so a page redirect is the key, and then use the menu system with wildcard.. that should work! thanks!