如何替换 Drupal Webform 验证器中的字段值?
在 Drupal Webform 中,我想在通过验证器时更改提交的值(例如,删除任何非数字字符)。
我按照验证器自述文件添加 hook_webform_validation_validators
并实现 hook_webform_validation_validate
挂钩。但是我无法找到返回参数来更改提交的 Web 表单值。
例如,如果用户输入 $12,340
,我希望提交失败并将 Webform 值更新为 12340
。当用户第二次提交时,新值12340
将通过验证器并被保存。
In a Drupal Webform, I'd like to alter the submitted value (e.g. to strip any non-numeric character) when going through the validator.
I follow the validator readme to add in hook_webform_validation_validators
and implement the hook_webform_validation_validate
hook. However I cannot locate a return parameter to alter the submitted webform value.
For example, if a user enters $12,340
, I'd like to fail the submission and update the webform value to 12340
.When the user submits the second time, the new value 12340
will pass the validator and be saved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为 Webform Validation 模块不允许您更改提交的值。我已经研究了它如何实现验证,如果您想更改提交的值,您可以在自己的模块中执行类似的操作。
以下代码部分取自 http://fleetthought.com /adding-additional-cck-validation-function-field-using-hookformalter 也来自 Webform Validation 模块代码。
在
form_alterations_link_validate
中,您可以使用 Drupal 的form_set_value()
方法在表单验证期间更改提交的表单值。I don't think that the Webform Validation module allows you to change the submitted values. I've looked at how it implements the validation and you can do something similar in your own module if you want to change the submitted value.
The following code is taken in part from http://fleetthought.com/adding-additional-cck-validation-function-field-using-hookformalter and also from the Webform Validation module code.
In the
form_alterations_link_validate
, you can use Drupal'sform_set_value()
method to change submitted form values during form validation.