在 Drupal 中通过 AHAH 传递参数

发布于 2024-12-02 07:47:11 字数 2102 浏览 4 评论 0原文

Drupal 6.22

我有一个空页面,除了一个带有两个输入值的表单,并且在提交时必须显示基于该值的查询结果。结果可能会显示在新窗口或同一页面上,唯一的要求是表单仍然易于访问。我尝试使用 AHAH 来实现此目的,但我还没有找到发送输入的方法。

这就是我现在所拥有的:

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',
            'wrapper' => '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"));
}

这会提交表单并将一些数据正确插入到entry-wrapper中。我知道我可以进行以下更改:

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));
}

并且我会返回 wharrgarbl,但静态值反而违背了这一点。

有没有办法在第一次提交后从该函数内访问 somemodule_form 的表单状态,或者我是否以完全错误的方式处理这个问题?

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',
            'wrapper' => '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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞取 2024-12-09 07:47:11

我不知道我是如何错过它的,但钩子表单的签名是 hook_form(&$node, $form_state)。 PHP 的宽恕有时可能是一种诅咒。不管怎样,出现了一个完全不相关的谷歌搜索 这个关于多步表单的问题,这就是我最终所做的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文