I would like to check if there is an error in my code I did not realize but why is my confirmation field's error message keep on displaying in the wrong filed? Suppose I have a password field and a password_confirmation field, but every time when user made a mistake in the password_confirmation field, the error displays in the password field instead. Here is a screenshot of the error.
And here is how I validate the input using FormRequest:
public function rules()
{
$rules = [
'login_email' => 'required',
'g-recaptcha-response' => 'required|captcha',
];
if ($this->request->has('password'))
{
$rules = [
'password' => 'required|confirmed|between:6,200',
'password_confirmation' => 'required',
'g-recaptcha-response' => 'required|captcha',
];
}
if ($this->request->has('old_password'))
{
$rules = [
'old_password' => 'required|between:6,200',
'password' => 'required|confirmed|between:6,200',
'password_confirmation' => 'required',
'g-recaptcha-response' => 'required|captcha',
];
}
return $rules;
}
Finally this is my html code
{!! Form::open(array('class' => 'form-horizontal login-form', 'url' => URL::route('postReset'), 'method' => 'POST')) !!}
<div class="form-group">
<div class="col-md-12 col-sm-12">
{!! Form::password('password', array('class' => 'form-control', 'placeholder' => 'New Password*')); !!}
{!! MessagerService::setInlineError($errors->first('password')) !!}
</div>
</div>
<div class="form-group">
<div class="col-md-12 col-sm-12">
{!! Form::password('password_confirmation', array('class' => 'form-control', 'placeholder' => 'Retype New Password*')); !!}
{!! MessagerService::setInlineError($errors->first('password_confirmation')) !!}
</div>
</div>
<div class="form-group">
<div class="col-md-12 col-sm-12">
{!! app('captcha')->display(); !!}
{!! MessagerService::setInlineError($errors->first('g-recaptcha-response')) !!}
</div>
</div>
<div class="form-group">
<div class="col-md-12 col-sm-12">
<button type="submit" class="btn btn-primary cbtn-login">Reset Password</button>
</div>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="hash" value="{{ Session::get('hash') }}">
{!! Form::close() !!}
because you have defined confirmed rule for your password field, all the errors related to password_confirmation will also be shown in password field.