1
我试过了其他帖子的解决方案数量,但仍然无法获得它的工作。拉拉维尔4同一视图上的两种形式
我对页面(视图)两种形式
{{ Form::open(array('action' => '[email protected]')) }}
....// form fields
<button type="submit" class="btn btn-primary">Change</button>
{{ Form::close() }}
<hr/>
{{ Form::open(array('action' => '[email protected]')) }}
....// second form fields
<button type="submit" class="btn btn-primary">Save Changes</button>
{{ Form::close() }}
然后在路线我
Route::post('/admin/preferences', ['uses' => '[email protected]', 'before' => 'csrf|admin']);
Route::post('/admin/preferences', ['uses' => '[email protected]', 'before' => 'csrf|admin']);
当我打在数据库提交按钮没有任何变化。即使我提交第二个表单,页面也会刷新,我会从FIRST表单获得成功消息。
是否因为这两个帖子中的路径相同?
更新:第一形式的输入字段:
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" <?php if ($settings['preferences_shop_mode'] == 0){ ?> checked="checked" value="1"<?php }else{ ?> value="0" <?php } ?>>
在这里,我检查,如果优先级为= 0到值设置为1,否则值= 0。在源我看到值为=1
这是正确的,因为在数据库中我有0
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked="checked" value="1">
这是控制器
public function shopMode() {
$preferences = Preferences::where('preferences_id', 1)->first();
if (!$preferences) {
App::abort(404);
}
Input::merge(array_map('trim', Input::all()));
$preferences->preferences_shop_mode = Input::get('onoffswitch');
$preferences->save();
return Redirect::to('/admin/preferences')->with('message', 'Shop mode changed successfully.');
}
任何想法为什么不在数据库中更新?
非常感谢你,但第二种形式不提交数据库的变化。我已经更新了我的问题。请你可以检查? –
这是一个完全不同的问题。复选框的行为与其余部分不同,如果未选中,则该字段不会根据请求到达。看到[这个问题](http://stackoverflow.com/questions/1809494/post-the-checkboxes-that-are-unchecked)它会有所帮助。让我知道! – alariva
但我总是有价值0或1.当它张贴我应该得到这个值,不是? –