是的,我在这个问题上看到了另外两个帖子,不幸的是我仍然无法使它工作,我的模态仍然关闭,我如何在显示错误时保持我的模态打开?我错过了什么吗?
控制器:
// check if the validator failed -----------------------
if ($validator->fails()) {
// get the error messages from the validator
$messages = $validator->messages();
// redirect our user back to the form with the errors from the validator
$input = Input::except('password', 'password_confirm'); //Get all the old input except password.
$input['autoOpenModal'] = 'true'; //Add the auto open indicator flag as an input.
return Redirect::back()
->withErrors($validator)
->withInput($input);
} else {
Blade.php:
<!-- Modal -->
<div id="register" class="modal fade" id="remoteModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">New User</h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form" method="POST" action="/manage_accounts" novalidate>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label class="control-label col-sm-3" for="name">Username:</label>
<div class="col-sm-5">
<input type="text" class="form-control" type="hidden" id="name" name="name" placeholder="Enter username">
@if ($errors->has('name')) <p class="help-block">{{ $errors->first('name') }}</p> @endif
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="password">Password:</label>
<div class="col-sm-5">
<input type="password" class="form-control" type="hidden" id="password" name="password" placeholder="Enter login password">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="password_confirm">Confirm Password:</label>
<div class="col-sm-5">
<input type="password" class="form-control" type="hidden" id="password_confirm" name="password_confirm" placeholder="Re-type password again">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="email">Email:</label>
<div class="col-sm-5">
<input type="email" class="form-control" type="hidden" id="email" name="email" placeholder="Enter email address">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-3" for="mobile">Phone Number:</label>
<div class="col-sm-5">
<input type="hpnum" class="form-control" type="hidden" id="mobile" name="mobile" placeholder="Enter handphone number">
</div>
</div>
<!--<div class="form-group">
<label class="control-label col-sm-3" for="officeEx">Office Extension:</label>
<div class="col-sm-5">
<input type="officeEx" class="form-control" id="officeEx" placeholder="Enter office extension">
</div>
</div> -->
<div class="form-group">
<label class="control-label col-sm-3" for="role_id">Role:</label>
<div class="col-sm-5">
<select class="form-control" type="hidden" id="role_id" name="role_id">
@foreach ($roles as $role)
<option value="{{ $role->id }}">{{ $role->role_description }}</option>
@endforeach
</select>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-5">
<button type="submit" class="btn btn-default">Register</button>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
if ({{ Input::old('autoOpenModal', 'false') }}) {
//JavaScript code that open up your modal.
$('#remoteModal').modal('show');
}
</script>
答案 0 :(得分:0)
我的错误,我只是意识到我为模态调用了两个id属性。无论如何,它已经解决了。