我正在使用BootstrapDialog打开编辑用户表单。它完美打开。
在我的列表页面中,当用户点击编辑按钮时,它将转到控制器并获取该用户信息,最后它将显示具有表单和更新的对话框按钮。 当他/她点击更新按钮时,它将调用其控制器的更新功能并验证所有字段并在出现某些错误时恢复到对话框。其他方面关闭对话框并显示成功消息。
我的问题是当有人留空到某个字段并且它在控制器中验证时,但它无法再显示该对话框。如何在该对话框中向用户显示错误消息。 我正在使用laravel 5.4。
修改按钮
<a class="btn btn-xs btn-primary edit_user_"
id="edit_user_<?php echo $v->id; ?>"
data-title="{{ $v->name }}"
href="edit-user/<?php echo $v->id; ?>">
<i class="glyphicon glyphicon-edit" title="Edit" ></i>
Edit
</a>
的js
$('.edit_user_').click(function(e){
e.preventDefault();
var url = $(this).attr('href');
BootstrapDialog.show({
title: $(this).attr('data-title') +"'s "+ 'Information',
message: $('<div></div>').load(url),
closable: true,
closeByBackdrop: false,
closeByKeyboard: false,
draggable: true,
buttons: [{
icon: 'glyphicon glyphicon glyphicon-save',
label: 'Update',
action: function(dialogRef) {
$('form').submit();
},
cssClass: 'btn-primary'
}]
});
return false;
});
控制器
public function updateSelectedUser(Request $request){
$id = $request->input('hId');
$oldImage = $request->input('oldImage');
$validator = $this->validate($request, [
'email' => 'required|email|unique:users,email,'.$id,
'name' => 'required|min:5',
'userimage' => 'required|image'
]);
//$path = Storage::putFile('userimages',$request['userimage']);
if ($validator->fails()) {
return Redirect::back()->with(array('error_code'=>1, 'uId'=>$id));
} else {
echo 'Validation Done';
}
}
我的edit.blade.php模板
<div class='row'>
<div class='col-md-12'>
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Edit User</h3>
</div>
<!-- form start -->
<form class="" role="form" method="post" enctype="multipart/form-data" files="true" action="<?php echo asset('regUser/update');?>" >
{{ csrf_field() }}
<input type="hidden" name="hId" value="{{ $info->id }}">
<div class="box-body">
<!-- Name -->
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" >Name</label>
<input id="name" type="text" class="form-control" name="name" value="{{ old('name', $info->name)}}" placeholder="Your Name" required >
@if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
@endif
</div>
<!-- Email -->
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" >Email</label>
<input id="email" type="text" class="form-control" name="email" value="{{ old('email', $info->email)}}" placeholder="Your Email" required >
@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif
</div>
<!-- Profile Pic-->
<div class="row">
<div class='col-md-6'>
<div class="form-group">
<label for="userimage" >Image</label>
<input id="userimage" type="file" name="userimage" required>
@if ($errors->has('userimage'))
<span class="help-block">
<strong>{{ $errors->first('userimage') }}</strong>
</span>
@endif
</div>
</div>
<div class='col-md-6'>
<div class="form-group">
<label for="userimage" >Old Image</label>
<img class="img-circle" src="{{asset('public/storage/'. $info->userimage )}}" alt="" style="height:50px;"/>
<input type="hidden" name="oldImage" value="{{ $info->userimage }}">
</div>
</div>
</div>
</div>
<!-- /.box-body -->
{!! Form::close() !!}
</div>
</div><!-- /.col -->
</div><!-- /.row -->