php - Laravel 请求总是返回 null
问题描述
所以我有这个观点
<form method="POST" action="/store">
<div class="control-group after-add-more">
<div class="form-group">
<label>Partner :</label>
<input type="text" class="form-control" id="partner" name="partner" value="" placeholder="Partner Name" />
</div>
<button class="btn btn-success add-more" type="button">
<i class="glyphicon glyphicon-plus"></i> Plus Partner</button>
<div class="copy hide">
<div class="control-group">
<div class="form-group">
<label> Partner :</label>
<input type="text" class="form-control" id="partner2" name="partner2" value="" placeholder="Partner Name" />
</div>
<button class="btn btn-danger remove" type="button">
<i class="glyphicon glyphicon-remove"></i>
Delete Partner</button>
</div>
</div>
<button type="submit">Submit</button>
</form>
这是我使用的 jquery
$(document).ready(function() {
$(".add-more").click(function() {
var html = $(".copy").html();
$(".after-add-more").after(html);
});
$("body").on("click", ".remove",function() {
$(this).parents(".control-group").remove();
});
});
但是当我尝试提交时,输入 partner2 正在返回空值
这是我的控制器
$kerma = Kerma::find(1)->get();
$kerma->partner()->createMany(['partner' => $request->input('partner')],['partner' => $request->input('partner2')])
有人对我有解决方案吗?提前致谢
解决方案
向表单提交您的请求时:
- 路由文件应该
POST
配置了方法。
Route::post('store', 'YourController@yourmethod');
- 将 CSRF 令牌添加到表单以防止
Page Expired
问题。因此,您的刀片文件应如下所示:
<form method="POST" action="{{url('store')}}">
@csrf
<div class="control-group after-add-more">
<div class="form-group">
<label>Partner :</label>
<input type="text" class="form-control" id="partner" name="partner" value="" placeholder="Partner Name" />
</div>
<button class="btn btn-success add-more" type="button">
<i class="glyphicon glyphicon-plus"></i> Plus Partner</button>
<div class="copy hide">
<div class="control-group">
<div class="form-group">
<label> Partner :</label>
<input type="text" class="form-control" id="partner2" name="partner2" value="" placeholder="Partner Name" />
</div>
<button class="btn btn-danger remove" type="button">
<i class="glyphicon glyphicon-remove"></i>
Delete Partner</button>
</div>
</div>
<button type="submit">Submit</button>
</form>
推荐阅读
- python - 如何加快在 Pandas 中填写日期的速度?
- c# - 将对象数组添加到另一个类 c#
- git - git fetch 不获取远程分支 - 如何获取所有远程
- excel - vba 运行时错误 91:在范围内查找日期
- html - 如何在 CSS 中调整这些图像的大小?
- continuous-integration - Bitbucket管道中的树稳定计时器?
- sql-server - SSIS 部署的包无法将驱动器标记映射到网络共享文件夹
- python - 使用 Flask API 而不是 render_template
- docker - 使用 Docker 将现有 Prestashop 部署到服务器
- r - R中矩阵的条件和减法