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

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

问题描述

Drupal 7. Webforms 3.x。



我正在尝试修改提交时的Webform组件值。我制作了一个名为'mos'的自定义模块,并添加了这个代码。

  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';
}
}
函数mos_contact_us_submit($ form,& $ form_state){
$ form ['#node'] - > {'webform'} ['components' ] ['1'] ='working@mos.com';
}

然而,当我看到数据库中的结果是常规的,不被覆盖的存储值。你可以帮助我知道我做错了什么吗?



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

解决方案

你应该把你的提交首先。

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

但是,如果要更改form_state中的某些变量,则应使用自定义_valadate函数。 / p>

Drupal 7. Webforms 3.x.

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?

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.

解决方案

You should to place your submit first.

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

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