我想在一个页面的网站上使用laravel建立一个联系表单,我似乎无法获得表单来验证用户输入并显示任何错误形式可能有。Laravel html表单不验证表单输入
email.blade.php:
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
{!! Form::open(['route' => 'mail', 'method' => 'post', 'role' => 'form', 'id' => 'footer-form']) !!}
<div class="form-group has-feedback">
{!! Form::label('first_name', null, ['class' => 'sr-only']) !!}
{!! Form::text('first_name', null, ['class' => 'form-control', 'placeholder' => 'First Name']) !!}
<i class="fa fa-user form-control-feedback"></i>
@if($errors->has('first_name'))
{{ $errors->first('first_name') }}
@endif
</div>
<div class="form-group has-feedback">
{!! Form::label('last_name', null, ['class' => 'sr-only']) !!}
{!! Form::text('last_name', null, ['class' => 'form-control', 'placeholder' => 'Last Name']) !!}
<i class="fa fa-user form-control-feedback"></i>
@if($errors->has('last_name'))
{{ $errors->first('last_name') }}
@endif
</div>
<div class="form-group has-feedback">
{!! Form::label('email', null, ['class' => 'sr-only']) !!}
{!! Form::email('email', null, ['class' => 'form-control', 'placeholder' => 'Email address']) !!}
<i class="fa fa-envelope form-control-feedback"></i>
@if($errors->has('email'))
{{ $errors->first('email') }}
@endif
</div>
<div class="form-group has-feedback">
{!! Form::label('textarea', null, ['class' => 'sr-only']) !!}
{!! Form::textarea('textarea', null, ['class' => 'form-control', 'rows' => 8, 'placeholder' => 'Message']) !!}
<i class="fa fa-pencil form-control-feedback"></i>
@if($errors->has('textarea'))
{{ $errors->first('textarea') }}
@endif
</div>
{!! Form::submit('Send', ['class' => 'btn btn-default']) !!}
{!! Form::close() !!}
Route: web.php:
Route::get('/ensignhospital', [
'as' => 'home',
'uses' => '[email protected]'
]);
Route::group(['before' => 'guest'], function() {
/*
* CSRF Protection
*
* */
Route::group(['before' => 'csrf'], function() {
Route::post('/ensignhospital', [
'as' => 'mail',
'uses' => '[email protected]'
]);
});
});
controller to handle for request:
class HomeController extends Controller {
public function home(){
return View('welcome');
}
public function postSendMail(ContactFormRequest $request){
if($request->fails()){
return Redirect::route('')
->withErrors()
->withInput();
}else{
return View('passed');
}
}
}
The form request validator class:
class ContactFormRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
'first_name' => 'required',
'last_name' => 'required',
'email' => 'required|email',
'message' => 'required'
];
}
}
问题表单在我没有输入有效输入时无法验证。我需要表单来验证用户输入和remain at the form position on the web page
。
please note:
我用.htaccess
文件,以获得这是对my computer
显示site root
为localhost/mylaravelproject
,而不是通常的localhost/mylaravelprojec/public
一个通常会看到一个新安装的laravel
网站。
你好@ollieread,我将发送一个邮件,验证用户输入值,这就是为什么我使用手动方法。 –