我无法从laravel中的模式中获取要提交的数据。当我使用下面的代码并点击“添加用户”按钮时,模式就会关闭,并且似乎不会调用控制器中的@store方法。数据不会提交到数据库
<div class="modal fade" id="addNew" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">New User</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
{!! Form::open(['method' =>'POST', 'action'=> 'UsersController@store', 'files'=>true, 'enctype'=>'multipart/form-data']) !!}
<div class="form-group {{$errors->has('firstName') ? 'has-error' : ''}}">
{!! Form::label('firstName', 'First Name:') !!}
{!! Form::text('firstName', null, ['class'=>'form-control', 'rows' => 3])!!}
@if($errors->has('firstName'))
{{$errors->first('firstName')}}
@endif
</div>
{{--most form data removed for simplicity--}}
<div class="form-group">
{!! Form::submit('Add user', ['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>发布于 2019-06-20 00:49:37
表单中缺少csrf令牌,该令牌将不允许在控制器中提交数据。在表单中添加“@csrf”,然后重试。
发布于 2019-06-20 00:38:07
当提交按钮的作用域超出form/div作用域,或者在提交按钮之前使用了任何其他按钮时,就会发生这种情况。为了简单起见,您没有粘贴其他代码,因此前面必须有一个按钮,否则会出现HTML标记问题。请检查所有Div标签格式(打开和关闭)或在此处从源代码添加HTML代码以获得更多帮助。谢谢你,快乐编码。
https://stackoverflow.com/questions/56671575
复制相似问题