在 webform 提交的值上使用 Hook_form_alter [英] Using Hook_form_alter on webform submitted values

查看:23
本文介绍了在 webform 提交的值上使用 Hook_form_alter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Drupal 7. 网络表单 3.x.

Drupal 7. Webforms 3.x.

我正在尝试在提交时修改 webform 组件值.我制作了一个名为mos"的自定义模块并将此代码添加到其中.

I am trying to modify a webform component value on submit. I made a custom module called 'mos' and added this code to it.

function mos_form_alter(&$form, $form_state, $form_id) { 
  if ($form_id == 'webform_client_form_43') {
      dsm($form['#node']->{'webform'}['components']['1']);
      $form['#submit'][] = 'mos_contact_us_submit';
    }
}
function mos_contact_us_submit($form, &$form_state) {
  $form['#node']->{'webform'}['components']['1'] = 'working@mos.com';
}

但是,当我查看数据库中的结果时,会存储常规的非覆盖值.你能帮我知道我做错了什么吗?

However when I look at the results in the database the regular, non-overridden value is stored. Can you help let me know what I am doing wrong?

最终我想取输入值并根据提供的内容输出一个电子邮件地址(例如.24 变成 bob@somewhere.com)但我想我可以自己弄清楚这部分.

Eventually I want to take the input value and output an email address based on what was provided (for example. 24 turns into bob@somewhere.com) But I think I can figure this part out myself.

推荐答案

你应该先提交.

array_unshift(
      $form['actions']['submit']['#submit'], 
      'mos_contact_us_submit'
);

但是,如果你想改变form_state中的一些变量,你应该使用自定义的_valadate函数.

However, if you want to change some variables in form_state, you should to using custom _valadate function.

这篇关于在 webform 提交的值上使用 Hook_form_alter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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