对 Web 表单提交的值使用 Hook_form_alter
Drupal 7。Webforms 3.x。
我正在尝试修改提交时的 Web 表单组件值。我制作了一个名为“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';
}
}
function mos_contact_us_submit($form, &$form_state) {
$form['#node']->{'webform'}['components']['1'] = '[email protected]';
}
但是,当我查看数据库中的结果时,会存储常规的、未覆盖的值。你能帮我知道我做错了什么吗?
最终我想获取输入值并根据提供的内容输出电子邮件地址(例如。24 变成 [电子邮件受保护])但我想我可以自己解决这部分。
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'] = '[email protected]';
}
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 [email protected]) But I think I can figure this part out myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该首先放置您的提交。
但是,如果您想更改 form_state 中的某些变量,则应该使用自定义 _valadate 函数。
You should to place your submit first.
However, if you want to change some variables in form_state, you should to using custom _valadate function.
我得到了它!非常感谢@dobeerman 为我指明了正确的方向。下面是最终运行的代码:
这样我可以保持电子邮件地址的私密性,但仍然使用 _GET 将变量传递到表单。有点奇怪的情况......但我们正在努力保持一些现有代码完整,所以这似乎是最好的路线。
我不小心弄乱了我的帐户创建,所以我不能给你信用 dobeerman,但我给管理员发了电子邮件,希望我能把它搞清楚,让你得到一些代表!
I got it! BIG Thanks to @dobeerman for pointing me in the right direction. Here is the code that ended up working:
This way I can keep email address private, but still pass variables to the form with _GET. Kind of a weird situation... but we are trying to keep some existing code intact, so it seemed like the best route.
I accidentally messed up my account creation, so I can't give you the credit dobeerman but I emailed the admins and hopefully I will get it straightened out to get you some rep!