I want to add an own validation (or submit) handler/function to my existing node form. I tried multiply things (following), but it does not work properly.
function MY_MODULE_form_alter(&$form, &$form_state, $form_id) {
$form['#validate'][] = 'MY_MODULE_handler';
//or
$form['actions']['submit']['#validate'][] = 'MY_MODULE_handler';
//or
$form['submit']['#submit'][] = 'MY_MODULE_handler';
//or
$form['#submit'][] = 'MY_MODULE_handler';
//or
array_unshift($form['#validate'], 'MY_MODULE_handler');
//or
$form['actions']['submit']['#submit'][]='MY_MODULE_handler';
}
But none of these attempts seem to work with my handler:
function MY_MODULE_handler($form, &$form_state){
dsm($form);
dsm($form_state);
}
Looking at the $form
variable in form_alter
I found that $form['actions']['submit']['#submit']
and $form['#validate']
have already a submit/validate handler.
But if I use one of the examples above, nothing is printed by dsm
. In addition it does not print the confirmation (of submitting) anymore! But if I use
function MY_MODULE_handler($form, &$form_state){
die('Handler was hit');
}
I see that the handler was hit.
What can be the reason? I need the handler to read two form fields and save them in one node attribute.
正如@ 2pha所建议的那样,我使用钩子HOOK_node_presave代替了附加的验证/提交处理程序,该钩子允许我解决我的问题(将表单中的值分配给一个node属性,请参见注释)。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.