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

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

问题描述

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



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

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

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

我该如何告诉本模块仅提及某个包含的形式类型?在提交数据时如何删除数据?

解决方案

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

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

或者,您可以在类似的回调中检查$ form参数



你缺少hook_form_alter的第三个参数,它应该是$ form_id,你的submit回调应该采用如下参数:

  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


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

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?

解决方案

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

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

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) { ... }

See also:

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天全站免登陆