我在Laravel表格中有2个开关,我已经将默认值设为0。 一提交,我就以表格形式获得所有价值,但这两个开关。
我想知道我是否做了一些我不想做的事情。
<div class="col-xs-2">
<label class="control-label">Multisite VPN</label> <br>
<input type="checkbox" name="vpn" id="vpn" value="0">
</div>
<div class="col-xs-2 mb10">
<label class="control-label">UPnP</label> <br>
<input type="checkbox" name="upnp" id="upnp" value="0">
</div>
<script type="text/javascript">
var vpn = $('#vpn');
var upnp = $('#upnp');
//Ativate the Switches
vpn.bootstrapSwitch('size', 'mini');
upnp.bootstrapSwitch('size', 'mini');
vpn.on('switchChange.bootstrapSwitch', function (event) {
if (vpn.is(':checked')) {
vpn.val(1);
} else {
vpn.val(0);
}
console.log('vpn: ' + vpn.val());
});
upnp.on('switchChange.bootstrapSwitch', function (event) {
if (upnp.is(':checked')) {
upnp.val(1);
} else {
upnp.val(0);
}
console.log('upnp: ' + upnp.val());
});
</script>
array:17 [▼
"_token" => "brXS4YGTGnD7QzkHuvbAyZsmSC8nUB9vxywB4bXK"
"name" => "silver"
"p_max_up" => "128"
"p_max_down" => "128"
"p_ip" => "111111111"
"p_netmask" => "2222222222"
"p_max_user" => "50"
"p_dns" => "333333333"
"p_dns2" => "4444444444"
"g_max_up" => "128"
"g_max_down" => "128"
"g_ip" => "5000000"
"g_netmask" => "6000000"
"g_max_user" => "22"
"g_dns" => "888888888"
"g_dns2" => "9999999999"
"g_portal" => "http://www.bunlongheng.com"
]
我将那些开关打开,我似乎得到了它
array:19 [▼
"_token" => "brXS4YGTGnD7QzkHuvbAyZsmSC8nUB9vxywB4bXK"
"name" => "silver"
"vpn" => "1" <--------- HERE
"upnp" => "1" <--------- HERE
"p_max_up" => "128"
"p_max_down" => "128"
"p_ip" => "111111111"
"p_netmask" => "2222222222"
"p_max_user" => "50"
"p_dns" => "333333333"
"p_dns2" => "4444444444"
"g_max_up" => "128"
"g_max_down" => "128"
"g_ip" => "5000000"
"g_netmask" => "6000000"
"g_max_user" => "22"
"g_dns" => "888888888"
"g_dns2" => "9999999999"
"g_portal" => "http://www.bunlongheng.com"
]
为什么2
输入仅在交换机为ON/True
时提交?
任何提示?
答案 0 :(得分:1)
当以HTML格式提交表单时,不会传输未选中的复选框(这是您的交换机的基础)。只有选中的复选框才会在提交时与表单一起传输。您可以使用隐藏的输入和/或javascript来记录是否曾经检查过复选框,而是传输这些值。