我有一个自定义模块,其表单在提交处理程序中包含表单重定向。
我正在使用hook_form_alter,并附加另一个自定义提交处理程序,总共有两个提交处理程序。重定向阻止我的第二个处理程序执行。当我删除重定向时,该功能完美地工作。关于如何防止重定向搞乱自定义提交处理程序的任何想法?
一些代码:
/*
Original form handler
*/
function example_form_handler($form, &$form_state) {
//some logic to insert into a db and then...
$form_state['redirect'] = '';
drupal_redirect_form($form_state);
}
/* Form alter in another file*/
function sm_integration_form_alter(&$form , &$form_state, $form_id) {
//this is altering the above form.
if ($form_id == "my_data_form" ){
//alert the form weight to be populated at last
$form['submit']['#weight'] = 5;
$form['#submit'][] = 'sm_integration_enable_submit';
}
}
/* This code is not being executed with the redirect */
function sm_integration_enable_submit(&$form, &$form_state) {
watchdog('sm_integration', 'This code does not execute with the redirect in the original module enabled');
}
答案 0 :(得分:2)
您似乎正在尝试重定向到主页
在重定向上指定主页(baseurl)$ url
$form_state['redirect'] = $GLOBALS['base_url'];