在 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.

相关文章