By laevensv@gmail.com on
Hello,
I'm writing a module who is about displaying a list of node.
First I've created a form, which contains a #AHAH properties in it.
I'm trying to display a list of node on the same page but nothing happens.
The question is : How do I show the results of my query after the form ?
function iew_autotextfields( &$form_state) {
[...]
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Search'),
);
return $form;
}
function iew_autotextfields_submit($form, &$form_state) {
if (!empty($form_state['iew_submission'])) {
return;
}
// Continue to handle submit processing.
$output='';
$type="associations";
$query = db_query("SELECT * FROM {node} WHERE type=%d", $type);
while ($row=db_fetch_array($query)) {
$output .= $row['title'];
}
if (isset($query)) {
drupal_set_message(t('Search submitted successfully.'));
}else {
drupal_set_message(t('There was an error. Please try again.'));
}
return $output;
}
Comments
Having the same issue...
I'm having the same issue as vallou17 did. I can print $output in drupal_set_message() function but nothing return in $output. And the only different is that I'm using Drupal 7.x.
Does anyone know the answer? Or should I write the db_select() somewhere else instead of in form_submit()? Thanks in advance.
Yeah I'd redirect somewhere
Yeah I'd redirect somewhere else using $form_state['redirect'] (I think that's right), then show whatever you want on that page.
Thank you for your prompt reply.
Hi, Andy,
Thank you for your prompt reply. I had tried $form_state['redirect'] as you suggested. And it works but I found that I can only pass the query parameters to the redirected form by using the URL like below.
For example, to redirect to 'my_form?type=page':
I found a similar issue in http://drupal.org/node/542646. But the sample code provided by quiet is not working.
Is there any other way to pass the parameters with 'post' rather than 'get'? Is 'redirect' with 'get' is the only way we can implement this?
You can get rid of the submit
You can get rid of the submit function, in which case control will return to the form. Since that function has access to $form_state, you can check that to see if there are submitted values.
Hi nevets
Hi, nevets,
Thank you for your reply. I did get rid of submit function as you suggested and the submitted values can be pass to the same form. But the query result cannot be printed out. Where did I do wrong? Below is the module that I wrote. Please help me to review it give me some advice. Thanks again.
Try removing
Try removing
$form_state['rebuild'] = TRUE;The result is the same after removing $form_state['rebuild'].
The result is the same after removing $form_state['rebuild'].