我有一个模式,当我的用户点击登录时会触发。
如果身份验证失败,我想重新定向回这个模式。
考虑到这一点,我想重新指导:
BTN
<a class="btn btn-default" id="btn-login" data-toggle="modal" data-target="#loginModal">Login</a>
模态
<!--Login Modal-->
<div class="light-skin modal fade" id="loginModal" tabindex="-1" role="form" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Login here</h4>
{{-- Session --}}
@include('layouts.session')
</div>
<div class="modal-body">
<form class="login-form" role="form" method="post" action="/">
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" name="username" placeholder="Enter Username" required>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Enter Password" required>
</div>
<button type="submit" class="btn btn-primary">Login</button>
{!! Form::token() !!}
</form>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
if($auth) {
return Redirect::to('/dist')
->with('success','You have been successfully logged in.')
;
}
else {
$url = URL::to('/').'#loginModal';
return Redirect::to($url)
->with('error','Username/Password Wrong or account has not been activated !')
->withInput(Input::except('password'))
->withErrors($validator);
}
没有什么是触发器。有人提示吗?
答案 0 :(得分:0)
感谢 @Tim Lewis 和 @Kryten 让我指向了正确的方向。
我确信有不止一种方法可以做到这一点,但这是我如何让我的工作。
<?php $error = Session::get('error'); ?>
// If there is error, the modal will be trigger.
@if(!empty($error) )
<script>
$(function() {
$('#loginModal').modal('show');
});
</script>
@endif