简体   繁体   English

Drupal表单错误重定向

[英]Drupal form error redirect

I need help for this problem: 我需要此问题的帮助:

In my Drupal 7 site i need to perform a redirect to a certain page if the login form is invalid, only in this occasion, and only for login form. 在我的Drupal 7站点中,如果登录表单无效,则仅在这种情况下,并且仅对于登录表单,我需要重定向到特定页面。 What is the best way to do this? 做这个的最好方式是什么? what function is called? 叫什么功能? Thanks in advance. 提前致谢。

You have to use hook_form_alter and add or alter the #validate options. 您必须使用hook_form_alter并添加或更改#validate选项。 Prefer the second method: 首选第二种方法:

function MYMODULE_form_alter(&$form, $form_state, $form_id) {
 if ($form_id == 'user_login') {
  $form['#validate'][] = 'MYMODULE_user_login_form_validate';
 }
}

function MYMODULE_user_login_form_validate($form, &$form_state) {
// Do some validation here. Better take the same codes from the validation functions below.
  if (...) {
   drupal_goto('CUSTOM_PATH');
  }
}

You can find the validation functions inside ROOT/modules/user/user.module file line 2113: 您可以在ROOT / modules / user / user.module文件行2113中找到验证功能

function user_login_default_validators() {
  return array('user_login_name_validate', 'user_login_authenticate_validate', 'user_login_final_validate');
}

Similar questions: 类似问题:

using hook_user_login method you can achieve the same, 使用hook_user_login方法可以实现相同的效果,



    /**
     * Implements hook_user_login();
     */
    function MODULE_NAME_user_login(&$edit, $account) {
        $url = 'PAGE_TO_BE REDIRECTED';
        if (isset($user->uid) && $user->uid > 0) {
            drupal_goto($url);
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM