[英]Laravel 7 Post contact form giving me error 419
so I've been trying to get a contact form to display as /contact
when using the form, and after submitting the form.所以我一直在尝试在使用表单时以及在提交表单之后显示为
/contact
的联系表单。 I'm getting Error 419 no matter what I seem to try.无论我尝试什么,我都会收到错误 419。
I created a resource controller called ContactController to get this to work, but if I use Route::resource
I'd be stuck using /contact/create
as the actual form.我创建了一个名为 ContactController 的资源 controller 以使其正常工作,但如果我使用
Route::resource
我将无法使用/contact/create
作为实际表单。
Here are my contact Routes for now:这是我现在的联系路线:
//Route::resource('contact', 'ContactController');
Route::post('/contact', 'ContactController@store');
Route::get('/contact', 'ContactController@create');
Here is my contact form:这是我的联系表格:
<form class="form" method="POST">
@error('name')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" id="name" class="form-control @error('name') is-invalid @enderror" placeholder="Enter Your Name....">
</div>
@error('email')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div class="form-group">
<label for="email">Email</label>
<input type="text" id="email" name="email" class="form-control @error('email') is-invalid @enderror" placeholder="johndoe@example.com">
</div>
@error('subject')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div class="form-group">
<label for="subject">Subject</label>
<input type="text" id="subject" name="subject" class="form-control @error('subject') is-invalid @enderror" placeholder="What is it you need?">
</div>
@error('content')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<div class="form-group">
<label for="content">Content</label>
<textarea class="form-control @error('content') is-invalid @enderror" name="content" id="content" rows="3" placeholder="Tell me more..."></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
I'm sure there's something I'm doing wrong, so what could it be?我确定我做错了什么,那会是什么?
To prevent cross-site request forgery attacks, Laravel requires CSRF "tokens" to be present in your forms.为防止跨站点请求伪造攻击,Laravel 要求 forms 中存在 CSRF“令牌”。 Change
改变
<form class="form" method="POST">
to至
<form class="form" method="POST">
@csrf
to include a hidden CSRF token field in the form.在表单中包含一个隐藏的 CSRF 令牌字段。
https://laravel.com/docs/7.x/csrf https://laravel.com/docs/7.x/csrf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.