Php 为什么我在提交时表格上出现CSRF令牌错误?
我的代币有问题Php 为什么我在提交时表格上出现CSRF令牌错误?,php,html,laravel,Php,Html,Laravel,我的代币有问题 TokenMismatchException in VerifyCsrfToken.php line 67: 我的文件中有多个表单,但这里有一个有问题: <!-- Modal --> {!! Form::open(['class' => 'sky-form sky-changes-3','url' => 'message-send','id' => 'sky-form3', 'style' => 'border:none']
TokenMismatchException in VerifyCsrfToken.php line 67:
我的文件中有多个表单,但这里有一个有问题:
<!-- Modal -->
{!! Form::open(['class' => 'sky-form sky-changes-3','url' => 'message-send','id' => 'sky-form3', 'style' => 'border:none']) !!}
<input type="hidden" name="contact_user_id" value="{{ $career_solution->user->id }}">
<input type="hidden" name="url" value="{{ url('view-career-solutions') }}/{{ $career_solution->id }}_{{ Slugify::slugify($career_solution->subject) }}">
<fieldset>
<section>
<label class="label">Subject</label>
<label class="input">
<i class="icon-append fa fa-tag"></i>
<input type="text" name="subject" id="subject">
</label>
</section>
<section>
<label class="label">Message</label>
<label class="textarea">
<i class="icon-append fa fa-comment"></i>
<textarea rows="4" name="message" id="message"></textarea>
</label>
</section>
</fieldset>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" style="bottom: 2px;position: relative">Close</button>
<button type="submit" class="btn-u btn-u-primary">Send message</button>
</div>
</div>
{!! Form::close() !!} </div>
在我的代码上方,我有以下几行代码:
@extends('layout.template')
@section('content')
<input type="hidden" name="_token" value="{{ csrf_token() }}">
@if($errors->any())
<h4>{{$errors->first()}}</h4>
@endif
发生了什么事?也许我应该在每个表单上手动添加CSRF令牌?我尝试添加@CSRF,{!!CSRF_field!!},但我遇到了相同的错误…CSRF令牌应该添加到表单中 您已将其添加到表单上方,显然在提交表单时不会传递到服务器 希望有帮助
<input type="hidden" name="_token" value="{{ csrf_token() }}">
把这个放在表格里
比如:
在应用程序中定义HTML表单时,应在表单中包含隐藏的CSRF令牌字段,以便CSRF保护中间件可以验证请求
<form method="POST" action="/profile">
@csrf //Include inside the form
...
</form>
以下输入必须始终位于表单内
您是否可以将CSRF令牌放置在表单中而不是表单外部?我不认为您在使用FormHelper时需要手动包含表单的CSRF_字段,因为它会自动为您创建或包含一个。你能检查一下你的or是否正确关闭吗?谢谢,我只是在每一张表格中添加了它,现在它工作了:你能把这个问题标记为已解决吗?可能是重复的,等等
<form method="POST" action="/profile">
@csrf //Include inside the form
...
</form>
<input type="hidden" name="_token" value="{{ csrf_token() }}">