vendredi 30 octobre 2015

Keep modal open and showing error laravel

Yes, I saw the other two post on this question unfortunately I still could not get it working, my modal still closes, how o I keep my modal open while showing the erors? am I missing out on something?

Controller:

// 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">&times;</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>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire