我在我的控制器中寫了一些表單驗證。Laravel電子郵件驗證顯示錯誤信息
$validator = Validator::make(Input::all(), [
'email' => 'email|required',
'password' => 'required'
]);
// If validation fails
if($validator->fails()) {
// Redirect to some place
return Redirect::route('account-sign-in-get')->withErrors($validator)->withInput();
} else {
// Attempt to sign in
}
在我的意見,我有以下:
@if($errors->has('email'))
<div class="alert alert-warning" role="alert">
{{ $errors->first('email') }}
</div>
@endif
我輸入一個字符串(不是一個有效的電子郵件地址),然後當我提出,我期待的是美國錯誤:「電子郵件必須是有效的電子郵件地址」
相反,我得到:‘電子郵件字段是必需的’
{{ Form::open(['route' => 'account-sign-in-post', 'role' => 'form']) }}
<div class="form-group">
{{ Form::label('email', 'E-mail', ['for' => 'email', 'class' => 'sr-only ']) }}
{{ Form::text('username', NULL, ['placeholder' => 'Email', 'id' => 'email', 'class' => 'form-control']) }}
@if($errors->has('email'))
<div class="alert alert-warning" role="alert">{{ $errors->first('email') }}</div>
@endif
</div><!-- End of .form-group -->
<div class="form-group">
{{ Form::label('password', 'Password', ['for' => 'password', 'class' => 'sr-only']) }}
{{ Form::password('password', ['placeholder' => 'Password', 'class' => 'form-control', 'id' => 'password']) }}
@if($errors->has('password'))
<div class="alert alert-warning" role="alert">{{ $errors->first('password') }}</div>
@endif
</div><!-- End of .form-group -->
{{ Form::submit('Sign in', ['class' => 'btn btn-primary btn-block']) }}
{{ Form::close() }}
釷請您閱讀本文。任何幫助表示讚賞:)
安置自己的形式?它看起來像沒有發送電子郵件輸入 – Laurence 2014-09-02 04:07:38
我知道我犯了錯誤。這是表單中的用戶名..將其更改爲電子郵件。奇蹟般有效!謝謝你,小夥伴 :) – arkhamDev 2014-09-02 04:17:06