如何在自定义表单处理程序中访问表单
我使用以下逻辑将自定义处理程序添加到另一个模块定义的表单中。我正在尝试对表单数据进行额外的处理。
function my_module_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'my_form') {
$form['#submit'][] = 'my_additional_submit_handler';
}
}
当然,我定义了自己的处理程序,名为 my_additional_submit_handler
,
function my_additional_submit_handler(){
}
但是如何将表单及其值传递给我的自定义处理程序?我尝试传递 &$form,但无法使用 dsm 在自定义处理程序中访问它。是否有特殊的语法可以使用自定义表单处理程序传递参数?
I'm using the following logic to add a custom handler to a form that's defined by another module. I'm trying to do additional processing on the form data.
function my_module_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'my_form') {
$form['#submit'][] = 'my_additional_submit_handler';
}
}
Of course I define my own handler called my_additional_submit_handler
function my_additional_submit_handler(){
}
but how do I pass the form and its values to my custom handler? I tried passing &$form, but could not access it in the custom handler with dsm. Is there a special syntax to pass in arguments with the custom form handler?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你试过这个吗?它应该按预期工作:
have you tried this ? It should work as expected:
您是否在
$form_state['values']['fieldName']
中查找数据?另外,正如 iKid 在他的代码示例中提到的,您的处理函数中需要参数$form 和 $form_state
。Are you looking for the data in
$form_state['values']['fieldName']
? Also, as iKid mensioned in his code sample you need the args$form and $form_state
in your handler function.