Hi everybody,
I am writing a module and a part of it is a form that allows the user to form a query: He or she can choose from some pop-ups the information she wants to view, and on submitting the form, she is going to see the result of the query AND the form again.
How can I achieve something like this with the Drupal-4.7 Forms-API?
What I do is the following: In my module 'test', I register a menu-item with a callback:
function test_menu($may_cache) {
//...
$items[] = array('path' => 'test/stats/jobs',
'title' => t('Queries'),
'callback' => 'test_stats_jobs_form',
'access' => user_access('query statistics'),
'type' => MENU_NORMAL_ITEM);
//...
}
The function test_stats_jobs_form() builds the form and renders it via a 'return drupal_get_form(...)' statement. The submission is handled in a function test_stats_jobs_form_submit(). So far no problems.
However, how can I tell drupal to display the result of the query in front of the form itself, once the user submitted the form? The only output I can generate is a text message that I bring up using drupal_set_message()!
I would be very glad to receive a hint, I'm completely lost here and could not find any relevant information on the web!
Thanks,
Kaspar
Comments
It has been asked before but not answered
I see that my question has been asked before (see "I know that" on http://drupal.org/node/82426) but not answered.
Anybody can provide a hint? Would be very heldful!
Kaspar
Solution
Answering myself, the following form definition code makes a form that outputs something before the form itself on submission:
It uses the #after_build feature to embed the output:
This also partially answers http://drupal.org/node/82426.
passing not working for me
when I pass the $form back for the second call, and do a var dump on $form, $form is empty.
I guess this is because
function test_stats_jobs_form()
is defined with no argument.
I am calling the function from menu. How do I do a menu callback and pass an argument?
I looked at these 2 pages but didn't see a way
http://api.drupal.org/api/group/menu/4.7
http://api.drupal.org/api/constant/MENU_CALLBACK/4.7