首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >验证失败时重定向Drupal 8表单

验证失败时重定向Drupal 8表单
EN

Drupal用户
提问于 2018-04-06 15:33:48
回答 1查看 1.9K关注 0票数 1

我有一个表单,在验证失败时,应该查询一个自定义/非Drupal表,如果该查询成功,则将用户重定向到一个只能通过登录状态访问的自定义页面(因此,我需要“伪造”成功的身份验证,即使该用户不存在于正式的Drupal user表中)。

对自定义表的查询本质上是在无法验证官方方式时以非Drupal格式检查辅助用户列表,如果成功,将将用户重定向到另一个页面,在那里他们可以选择Drupal用户名和密码组合,以便在系统中注册它们/创建一个正式帐户。

这是我的表单验证方法中的相关代码:

代码语言:javascript
复制
if ($this->userAuth->authenticate($form_state->getValue('name'), $password) == FALSE) {
    // other stuff
    $uid = $this->userAuth->authenticate($form_state->getValue('name'), $password);
    $form_state->set('uid', $uid);

    $response = new TrustedRedirectResponse('/path/destination');
    $form_state->setResponse($response);
}

我也尝试过这样做,而不是使用新的TrustedRedirectResponse:

代码语言:javascript
复制
    $redirect_path = "/path/destination";
    $url = url::fromUserInput($redirect_path);
    $form_state->setRedirectUrl($url);
EN

回答 1

Drupal用户

回答已采纳

发布于 2018-04-07 04:05:03

如果您希望重定向立即发生,您可以这样做:

代码语言:javascript
复制
use Symfony\Component\HttpFoundation\RedirectResponse;


$response = new RedirectResponse('/path/destination');

$response->send();
票数 1
EN
页面原文内容由Drupal提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://drupal.stackexchange.com/questions/259334

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档