Php Laravel 5.3表单重定向到post登录
我有一张表格应该转到OrgController@store发布到页面上。发生的情况是,它似乎重定向到/并且从未进入OrgController中的“我的存储”函数 根据Firebug中我的网络选项卡,它发布到/org/add,然后出于某种原因发出GET登录请求,即使我注释掉了对Auth中间件的调用 GET登录请求显示我已登录,然后将我重定向到Laravel Auth RedirectIfAuthenticated设置的位置。(在本例中为/) 基本上我想我的路由尊重身份,但也张贴到我的表单 我的路线是这样的Php Laravel 5.3表单重定向到post登录,php,laravel,routes,laravel-5.3,Php,Laravel,Routes,Laravel 5.3,我有一张表格应该转到OrgController@store发布到页面上。发生的情况是,它似乎重定向到/并且从未进入OrgController中的“我的存储”函数 根据Firebug中我的网络选项卡,它发布到/org/add,然后出于某种原因发出GET登录请求,即使我注释掉了对Auth中间件的调用 GET登录请求显示我已登录,然后将我重定向到Laravel Auth RedirectIfAuthenticated设置的位置。(在本例中为/) 基本上我想我的路由尊重身份,但也张贴到我的表单 我的路线
Route::group(['prefix' => 'org'], function () {
Route::get('search', 'OrgController@search');
Route::get('browse', 'OrgController@browse');
Route::get('add', 'OrgController@add');
Route::post('add', 'OrgController@store');
});
<form method="post" action="">
<div class="form-group">
<label for="parent_org">Parent Organization</label>
<select class="form-control" id="parent_org" required="true">
<option>Org Unit 1</option>
<option>Org Unit 2</option>
<option>Org Unit 3</option>
<option>Org Unit 4</option>
</select>
</div>
<div class="form-group">
<label for="org_name">Org Unit Name</label>
<input type="text" class="form-control" id="org_name" required="true">
</div>
<div class="checkbox">
<label><input type="checkbox">Will users be added directly to this organization unit?</label>
</div>
<button type="submit" class="btn btn-primary">Add Org</button>
</form>
我的表格是这样的
Route::group(['prefix' => 'org'], function () {
Route::get('search', 'OrgController@search');
Route::get('browse', 'OrgController@browse');
Route::get('add', 'OrgController@add');
Route::post('add', 'OrgController@store');
});
<form method="post" action="">
<div class="form-group">
<label for="parent_org">Parent Organization</label>
<select class="form-control" id="parent_org" required="true">
<option>Org Unit 1</option>
<option>Org Unit 2</option>
<option>Org Unit 3</option>
<option>Org Unit 4</option>
</select>
</div>
<div class="form-group">
<label for="org_name">Org Unit Name</label>
<input type="text" class="form-control" id="org_name" required="true">
</div>
<div class="checkbox">
<label><input type="checkbox">Will users be added directly to this organization unit?</label>
</div>
<button type="submit" class="btn btn-primary">Add Org</button>
</form>
我正在使用自定义身份验证提供程序来扩展Laravel内置的身份验证
提前谢谢你
问题是我忘了我已经输入了异常处理程序
if ($exception instanceof TokenMismatchException) {
return redirect('/login');
}
我的表格中也没有我的CSRF代币。因此,它抑制了无效的CSRF令牌错误,并重定向到登录
。。吸取的教训。Woops
问题是我忘了我已经输入了异常处理程序
if ($exception instanceof TokenMismatchException) {
return redirect('/login');
}
我的表格中也没有我的CSRF代币。因此,它抑制了无效的CSRF令牌错误,并重定向到登录
。。经验教训。出于安全目的,请勿禁用登录页面中的令牌或任何带有post请求的url。只需在表单字段中添加
{{csrf_token()}}
。csrf_令牌返回带有令牌的输入隐藏字段。它可以保护您的表单免受外界的滥用攻击
<form method="post" action="">
<div class="form-group">
<label for="parent_org">Parent Organization</label>
Add csrf_token anywhere inside your form
{{csrf_token()}}
<select class="form-control" id="parent_org" required="true">
<option>Org Unit 1</option>
<option>Org Unit 2</option>
<option>Org Unit 3</option>
<option>Org Unit 4</option>
</select>
</div>
<div class="form-group">
<label for="org_name">Org Unit Name</label>
<input type="text" class="form-control" id="org_name" required="true">
</div>
<div class="checkbox">
<label><input type="checkbox">Will users be added directly to this organization unit?</label>
</div>
<button type="submit" class="btn btn-primary">Add Org</button>
</form>
上级组织
在表单中的任意位置添加csrf_令牌
{{csrf_token()}}
组织单元1
组织单元2
组织单元3
组织单元4
组织单位名称
是否将用户直接添加到此组织单元?
添加组织
出于安全目的,请勿禁用登录页面中的令牌或任何带有post请求的url。只需在表单字段中添加{{csrf_token()}}
。csrf_令牌返回带有令牌的输入隐藏字段。它可以保护您的表单免受外界的滥用攻击
<form method="post" action="">
<div class="form-group">
<label for="parent_org">Parent Organization</label>
Add csrf_token anywhere inside your form
{{csrf_token()}}
<select class="form-control" id="parent_org" required="true">
<option>Org Unit 1</option>
<option>Org Unit 2</option>
<option>Org Unit 3</option>
<option>Org Unit 4</option>
</select>
</div>
<div class="form-group">
<label for="org_name">Org Unit Name</label>
<input type="text" class="form-control" id="org_name" required="true">
</div>
<div class="checkbox">
<label><input type="checkbox">Will users be added directly to this organization unit?</label>
</div>
<button type="submit" class="btn btn-primary">Add Org</button>
</form>
上级组织
在表单中的任意位置添加csrf_令牌
{{csrf_token()}}
组织单元1
组织单元2
组织单元3
组织单元4
组织单位名称
是否将用户直接添加到此组织单元?
添加组织