我目前正在通过模态框处理登录/注册项目(所以我点击登录按钮和一个漂亮的模态显示窗体)。验证重定向后保持模态打开
我使用基金会5的揭示模式来容纳我的登录表单,但是当表单被提交时,模式关闭的验证错误。发生这种情况的原因是因为我正在重定向到登录表单所在的路径,并且在该路由中需要单击按钮来触发模式。
我想知道的是,有什么我可以设置,以便模态保持打开,如果有验证错误或异常(帐户未找到等)。所以如果有验证错误模态保持打开状态。
寻找任何类型的解决方案。我的代码如下所示。
登录功能
public function postLogin()
{
// Declare the rules for the form validation
$rules = array(
'email' => 'required|email',
'password' => 'required|between:3,32',
);
// Create a new validator instance from our validation rules
$validator = Validator::make(Input::all(), $rules);
// If validation fails, we'll exit the operation now.
if ($validator->fails())
{
// Ooops.. something went wrong
return Redirect::back()->withInput()->withErrors($validator);
}
try
{
// Try to log the user in
Sentry::authenticate(Input::only('email', 'password'), Input::get('remember-me', 0));
// Get the page we were before
$redirect = Session::get('loginRedirect', 'dashboard');
// Unset the page we were before from the session
Session::forget('loginRedirect');
// Redirect to the users page
return Redirect::to($redirect)->with('success', Lang::get('auth/message.signin.success'));
}
catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
{
$this->messageBag->add('email', Lang::get('auth/message.account_not_found'));
}
catch (Cartalyst\Sentry\Users\UserNotActivatedException $e)
{
$this->messageBag->add('email', Lang::get('auth/message.account_not_activated'));
}
catch (Cartalyst\Sentry\Throttling\UserSuspendedException $e)
{
$this->messageBag->add('email', Lang::get('auth/message.account_suspended'));
}
catch (Cartalyst\Sentry\Throttling\UserBannedException $e)
{
$this->messageBag->add('email', Lang::get('auth/message.account_banned'));
}
// Ooops.. something went wrong
return Redirect::back()->withInput()->withErrors($this->messageBag);
}
登录模式
<div id="myModalLogin" class="reveal-modal small" data-reveal>
<h2>Login</h2>
<form method="post" action="{{ route('login') }}">
{{-- CSRF Token --}}
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
{{-- Email --}}
<label for="email"> Email
<input type="text" name="email" id="email" value="{{ Input::old('email') }}" />
</label>
{{ $errors->first('email', '<label class="error">:message</label>') }}
{{-- Password --}}
<label for="password"> Email
<input type="password" name="password" id="password" value=""/>
</label>
{{ $errors->first('password', '<label class="error">:message</label>') }}
{{-- Remember me --}}
<input name="remember-me" value="1" id="remember-me" type="checkbox"><label for="remember-me">Remember me</label>
<hr>
{{-- Form Actions --}}
<button type="submit" class="button">Sign in</button>
<a href="{{ route('forgot-password') }}">I forgot my password</a>
<a class="close-reveal-modal">×</a>
</div>
我试过但仍然似乎没有工作。你提供的第二个选项绝对是我正在寻找的解决方案,只是无法让它工作'$(document).ready(function(){if({{(isset($ autoOpenModal)&& $ autoOpenModal)'true': ''false'}}){('#myModalLogin')。foundation('reveal','open'); } });'试过了,它不起作用。 – jackthedev
是的,进入控制台时,模式工作。包含jQuery,没有控制台错误。我注意到,当我查看源码时,代码显示为'$(document).ready(function()if(false){('#myModalLogin')。foundation('reveal','open') ; } });'即使在我得到验证错误后它仍然是假的。 – jackthedev
@totymedi是这是我的重定向'返回Redirect :: back() - > withInput() - > withErrors($ validator) - > with('autoOpenModal',true);'但它仍然错误,即使重定向后。 – jackthedev