Drupal 6.22
I have an empty page except for a form that takes two input values and, when submitted, must display the result of a query based on that. The result may be displayed in a new window or on the same page, the only requirement is that the form is still easily accessible. I've tried to use AHAH to achieve this but I haven't found a way to send along the input.
This is what I have now:
function somemodule_menu()
{
$items['somemodule/js'] = array(
'page callback' => 'somemodule_js',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function somemodule_form()
{
$form = array();
$format = 'd/m/Y';
$default = 'Y-m-d 00:00:00';
$form['from'] = array(
'#type' => 'date_popup',
'#title' => t('From'),
'#default_value' => date($default),
'#date_format' => $format,
'#required' => TRUE
);
$form['to'] = array(
'#type' => 'date_popup',
'#title' => t('To'),
'#default_value' => date($default, mktime(0, 0, 0, date('n') + 6)),
'#date_format' => $format,
'#required' => TRUE
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Send'),
'#ahah' => array(
'path' => 'somemodule/js',
'wrapp开发者_StackOverflow社区er' => 'entry-wrapper',
'method' => 'replace',
'progress' => array(
'type' => 'bar',
'message' => t('Please wait...')
)
)
);
return $form;
}
function somemodule_js()
{
return drupal_json(array('status' => TRUE, 'data' => "some data"));
}
This submits the form and correctly inserts some data
into entry-wrapper
. I know that I can make the following changes:
function somemodule_menu()
{
$items['somemodule/js/somevar'] = ...
}
function somemodule_form()
{
...
$form['submit'] = array(
'#ahah' => array(
'path' => 'somemodule/js/wharrgarbl',
...
}
function somemodule_js($string)
{
return drupal_json(array('status' => TRUE, 'data' => $string));
}
and I'll get wharrgarbl
back, but a static value rather defeats the point.
Is there a way to access the form state of somemodule_form
from within that function after the first submission or am I going about this entirely the wrong way?
I don't know how I missed it but the signature for hook form is hook_form(&$node, $form_state)
. PHP's forgiveness can be a curse sometimes. Anyway, a completely unrelated Google search turned up this question about multistep forms, which is what I ended up doing.
精彩评论