ark*_*Dev 1 php validation 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
}
Run Code Online (Sandbox Code Playgroud)
在我看来,我有以下几点:
@if($errors->has('email'))
<div class="alert alert-warning" role="alert">
{{ $errors->first('email') }}
</div>
@endif
Run Code Online (Sandbox Code Playgroud)
我输入一个字符串(不是有效的电子邮件地址),然后在提交时,我看到一个错误,指出:“电子邮件必须是有效的电子邮件地址”
相反,我得到:“电子邮件字段为必填”
{{ 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() }}
Run Code Online (Sandbox Code Playgroud)
谢谢您阅读此篇。任何帮助表示赞赏:)
错误的形式。
特别是在我们有用于用户名的文本输入的地方。
{{ Form::text('username', NULL, ['placeholder' => 'Email', 'id' => 'email', 'class' => 'form-control']) }}
Run Code Online (Sandbox Code Playgroud)
应该用于电子邮件:
{{ Form::text('email', NULL, ['placeholder' => 'Email', 'id' => 'email', 'class' => 'form-control']) }}
Run Code Online (Sandbox Code Playgroud)