I clicked on login, but the right side of register the errors shows up.
this is my view
<!-- REGISTER AREA LEFT SIDE -->
<div class="col-md-6">
<h3>Member Login</h3>
@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form role="form" method="POST" action="{{ URL::route('login') }}">
....
</div>
<!-- REGISTER AREA RIGHT SIDE -->
<div class="col-md-6">
<h3>Member Registration</h3>
@if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form role="form" method="POST" action="{{ URL::route('register') }}">
....
</div>
and this is my controller return
return Redirect::back()
->withInput()
->withErrors($validation);
any way to rename the error with login_error
and register_error
? how to separate them into two variables, cause it conflict and shows both message on right side.
Your fields have names in html, and laravel binds the error to their names so that you can display the error for a specific field, so you can wrap the login form error block with something like:
@if($errors->first('login_email') || $errors->first('login_password'))
// ...
@endif
and the registration form error block with:
@if($errors->first('register_email') || $errors->first('register_password') || $errors->first('register_password_bis'))
// ...
@endif
This may not be the best solution, but I know it works and it will avoid to use hacks. Plus it does not add too much boilerplate as you do not have a lot of fields there.
Depending on how you built your constructor, you could also flash a message in the session in order to tell your view which form you validated:
Login
@if (count($errors) > 0 && Session::has('validated_login_form') == true)
// ...
@endif
Registration
@if (count($errors) > 0 && Session::has('validated_registration_form') == true)
// ...
@endif
Another way of doing it would be to look how the withErrors($validation)
function works in Laravel sources and see if you can reproduce it yourself but naming $errors differently depending on the form you just validated.