在drupal中提交后更改表单数据 [英] Change form data after submit in drupal

查看:24
本文介绍了在drupal中提交后更改表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些内容类型表单中,我添加了一个复选框.选中此复选框后,我想删除一些提交的数据.

in some content type form I added a checkbox. When this checkbox is checked I want to remove some of the submitted data.

为此,我创建了一个自定义模块 (my_module.module):

To do so I created a custom module (my_module.module):

function my_module_form_alter(&$form, &$form_state) {
    // ...
    $form['#submit'][] = 'my_module_form_alter_submit';
}

function my_module_form_alter_submit($form_id, $form_values) {
    drupal_set_message(t('Submit Function Executed!'));
}

我怎样才能告诉这个模块只引用某个包含类型的表单?提交时如何删除数据?

How can I tell this module to refer only to the form of a certain containt type? And how can I remove data when it is submitted?

推荐答案

假设您正在更改节点编辑表单,您可以有条件地添加提交回调,例如(在您的 hook_form_alter 中):

Assuming you are altering a node edit form, you can either conditionally add the submit callback such as (in your hook_form_alter):

if(isset($form['#node']) && $form['type']['#value'] == 'page') {
    $form['#submit'][] = 'my_module_form_alter_submit';
}

或者,您可以以类似的方式检查提交回调中的 $form 参数.

or, you could check the $form argument in the submit callback in a similar fashion.

您缺少 hook_form_alter 的第三个参数,它应该是 $form_id,并且您的提交回调应该采用如下参数:

You are missing the third argument to the hook_form_alter which should be $form_id, and your submit callback should take the arguments such as:

function my_module_form_alter_submit($form, &$form_state) { ... }

另见:

http://api.drupal.org/api/drupal/developer%21hooks%21core.php/function/hook_form_alter/6

http://api.drupal.org/api/drupal/developer%21topics%21forms_api.html/6

这篇关于在drupal中提交后更改表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆