1

BootstrapDialog を使用して編集ユーザー フォームを開きます。完璧に開きます。

リストページでユーザーが編集ボタンをクリックすると、コントローラーに移動してそのユーザー情報を取得し、最後にフォームと更新ボタンのあるダイアログボックスを表示します。更新ボタンをクリックすると、コントローラーの更新機能が呼び出され、すべてのフィールドが検証され、エラーがあればダイアログ ボックスに戻ります。それ以外の場合は、ダイアログ ボックスを閉じて、成功メッセージを表示します。

私の質問は、誰かがフィールドに空白のままにしてコントローラーで検証したときに、ダイアログ ボックスを表示できなくなったときです。そのダイアログボックスでユーザーにエラーメッセージを表示するにはどうすればよいですか。私はlaravel5.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 -->

4

0 に答える 0