Drupal 6,FAPI表单提交两次,为什么?

发布于 2024-11-10 07:10:06 字数 953 浏览 1 评论 0原文

使用此代码:

drupal_set_message('form id: ' .$form_id. ' send with '. $delta . ' and field: '. $field);

我注意到每次单击 £send" 按钮时,表单都会提交两次,所以我看到如下内容:

表单 ID:formname2 发送 3 和 字段 xxx 表单 id: formname2 发送方式 4、字段xxx

$delta 发生变化,是 cck 多组字段的增量(我正在将一个新字段插入到 cck 内容中)。这是提交函数:

function IngredientsForm_submit($form, &$form_state){
    global $user;
    $ls_id = $user->ls_id;
    $current_ls = node_load($ls_id);    
    $delta = $form_state['values']['delta'];
    $field = $form_state['values']['field_name'];
    $form_id = $form_state['values']['form_id'];
    $current_ls->field_descrizione_ingrediente[$delta]['value'] = $field;
    drupal_set_message('form id: ' .$form_id. ' send with delta: '. $delta . ' and field: '. $field);
    node_save($current_ls);             
}

奇怪,只有第一次提交的东西似乎保存在数据库中,所以保存的数据是正确的......

知道为什么会有双重提交吗?

using this code:

drupal_set_message('form id: ' .$form_id. ' send with '. $delta . ' and field: '. $field);

I notice that every time I click the £send" button, the form is submitted twice, so I see something like this:

form id: formname2 send with 3 and
field xxx form id: formname2 send with
4 and field xxx

the $delta, that one which change, is the delta of a cck multigroup field (i'm inserting a new field into a cck content). Here's the submit function:

function IngredientsForm_submit($form, &$form_state){
    global $user;
    $ls_id = $user->ls_id;
    $current_ls = node_load($ls_id);    
    $delta = $form_state['values']['delta'];
    $field = $form_state['values']['field_name'];
    $form_id = $form_state['values']['form_id'];
    $current_ls->field_descrizione_ingrediente[$delta]['value'] = $field;
    drupal_set_message('form id: ' .$form_id. ' send with delta: '. $delta . ' and field: '. $field);
    node_save($current_ls);             
}

Strange, thing only the first submission seems to be saved in the database, so the saved data is correct...

Any idea why there is a double submition?

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

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

发布评论

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

评论(2

静若繁花 2024-11-17 07:10:06

我会检查表单变量并查看提交函数是否列出多次。这可能位于 $form['#submit'] 或 $form['buttons']['submit']['#submit'] 中,具体取决于这是自定义表单还是默认节点表单。

看来提交函数被调用了两次,但 node_save 正在执行更新而不是插入,因此数据库显示正确。

如果您没有看到重复的提交处理程序被调用,那么也许可以发布构建/更改表单的代码。

I would examine the form variable and see if the submit function is listed more than once. This might be in $form['#submit'] or $form['buttons']['submit']['#submit'] depending on if this is a custom form or a default node form.

It appears the submit function is being called twice but the node_save is doing an update rather than an insert so the database appears correct.

If you do not see a duplicate submit handler being called, then perhaps post your code that builds/alters the form.

白况 2024-11-17 07:10:06

我遇到了同样类型的问题,我认为这是 drupal 流程形成的方式。 以下行移动到提交函数中,您会发现该消息只会显示一次。

drupal_set_message('form id: ' .$form_id. ' send with delta: '. $delta . ' and field: '. $field);"

如果在保存数据后将

I was having the same type of problem, I think it is the way drupal processes forms. If you move the following line

drupal_set_message('form id: ' .$form_id. ' send with delta: '. $delta . ' and field: '. $field);"

into your submit function after you have saved your data, you will find that the message will only show up once.

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