I apologize in advance if this question has been answered a hundred times before. Drupal noob, lifelong programmer here.

What I want is to split a page into two regions... a top-half where the user enters multiple database search terms... and a bottom-half where the user is presented with a nicely formatted table of results matching the search terms. I was able to do this easily enough in page-embedded PHP, but wanted instead to do it in a module (seemed more "appropriate).

Starting with the incredibly enlightening CRUD scaffolding example, I was able to "sort of" get this to work.

1) I implemented a theme hook to append the table to the end of the rendered form.
2) In the submit function, I store the form values in $form_state['storage'] and set $form_state['rebuild'] to true.

This works reasonably well as long as the table I build in step 1 doesn't use the fancy pager/sortable feature used in the scaffolding example. Well I want it all, I need that sort... :)

So am I just going about this all wrong? Should I split the page into two distinct regions (blocks?) where one (the form) feeds the other (the table)? Is there a good archetype demonstrating this?

Again, thanks in advance. Please be easy on me.

Mark

Comments

markallenneil’s picture

Never mind on this one... found a solution.

1) Store the parameters to populate the form on reload in $form_state['storage'] in the form's submit method.
2) In the form method, let $params = $_REQUEST and fetch what you need... like $params['name'].
3) When constructing the form, include a statement like ( '#default_value' => isset($params['name']) ? $params['name'] : '', ) for each field.

This method works whether you hit submit or use the table header sort method.

Mark