Это то, что я хочу. Когда я нажал кнопку «Сохранить», в случае ошибки мой модал не исчезнет. И мой вклад останется.
Мой модал исчезнет, если регистрация прошла успешно
У меня есть здесь коды и использование Laravel.
Вот вид и контроллер
Просмотр страницы:
{{ Form::open(array('url'=>'main/branches')) }}
<div class="modal fade" id= "myModalCreate" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" 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"><center>Create Branch</h4>
</div>
<div class="modal-body">
@if(Session::has('error'))
<div>{{ Session::get('error') }}</div>
@endif
<table>
<tr>
<td style="padding:10px;"><label>Branch Name</label></td>
<td width="10" valign="top" style="padding:10px;"><b>:</td>
<td><input type="text" class="form-control" name="branch_name" id="branch_name" pattern="[a-zA-Z0-9- ]{5,30}" onkeyup="autocap(this.id)" maxlength = "30" title="Accepts only letters, numbers, spaces, dash(-), 5 - 20 characters" autocomplete = "off" value="{{ Input::old('branch_name') }}" required></td>
</tr>
<tr>
<td style="padding:10px;"><label>Branch Code</label></td>
<td valign="top" style="padding:10px;"><b>:</td>
<td><input type="text" class="form-control" name="branch_code" id="branch_code" pattern="[a-zA-Z0-9-]{6,8}" maxlength = "8" title="Accepts only combination of letters and numbers, no spaces, 6 - 8 characters" style="text-transform:uppercase;" onkeyup="javascript:this.value=this.value.toUpperCase();" autocomplete = "off" style="text-transform:uppercase" required></td>
</tr>
<tr>
<td valign="top" style="padding:10px;"><label>Location</label></td>
<td valign="top" style="padding:10px;"><label>:</label></td>
<td><textarea class="form-control" name="branch_location" id="branch_location" pattern="[a-zA-Z0-9-. ]{5,200}" onkeyup="autocap(this.id)" maxlength = "200" title="Accepts only letters, numbers, spaces, dash(-), dot(.), 5 - 50 characters" autocomplete = "off" rows="5" required></textarea></td>
</tr>
</table>
</div>
<div class="modal-footer">
<button class="btn btn-primary">Save</button>
<button class="btn btn-default" data-dismiss="modal" onclick="clearAddBranch()">Close</button>
</div>
</div>
</div>
</div>
{{ Form::close() }}
контроллер
public function postBranches() {
$branch_code = DB::table('branches')->where('branch_code', Input::get('branch_code'))->first();
if($branch_code) {
return Redirect::to('main/branches')->with('error','<button type="button" class="close" data-dismiss="alert" style="margin:10px 5px 10px 5px;">×</button><h5 class="alert alert-danger"><span class="glyphicon glyphicon-exclamation-sign"></span><strong> Warning! </strong>Branch code already exists.</h5>');
} else {
$branch = new Branch;
$branch->branch_name = Input::get('branch_name');
$branch->branch_code = Input::get('branch_code');
$branch->branch_location = Input::get('branch_location');
$branch->branch_logo = "blank.png";
$branch->status = "1";
$branch->save();
return Redirect::to('main/branches')->with('message', '<button type="button" class="close" data-dismiss="alert" style="margin:5px 10px;">×</button><h5 class="alert alert-info"><span class = "glyphicon glyphicon-ok-sign"></span><strong> Success! </strong>New Branch has been successfully added!</h5>');
}
}
Задача ещё не решена.
Других решений пока нет …