PHP:是否可以自动获取所有过帐的数据,并且取消选中多个复选框? [英] PHP: Possible to automatically get all POSTed data And Multiple checkbox unchecked?

查看:46
本文介绍了PHP:是否可以自动获取所有过帐的数据,并且取消选中多个复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友你好,我遇到麻烦了.

Hello friends i have a trouble.

我正在尝试使用此代码来动态获取表单的变量和值,但是有一个不计其数的数字复选框,该复选框可能带有或不带有标记,我想知道如何获得关闭或"0" 如果没有标记为复选框,则这些数据已被使用.ajax和数据:

I'm trying to use this code to get dynamically, variables and values of a form, but there is a countless number checkbox, which may or not marked, I would like to know how can I get an off or "0" in case not this a checkbox labeled, these data have been used .ajax and data:

复选框的简短示例:

<input name="p-sis-0110-1" type="checkbox">
<input name="p-sis-0110-2" type="checkbox">
<input name="p-sis-0110-3" type="checkbox">
<input name="p-sis-0110-4" type="checkbox">
<input name="p-sis-0110-5" type="checkbox">
<input name="p-sis-0110-6" type="checkbox">

<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">
<input name="input[]" type="checkbox">

Ajax:

.$("#formarea").serialize()

PHP:

foreach ($_POST as $key => $value){
    echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>"
}

感谢您为解决这一小难题所提供的帮助.

I appreciate any help to solve this little dilemma.

推荐答案

仅提交"成功"控件.未选中的复选框或单选按钮不是"成功".

Only "successful" controls are submitted. An unchecked checkbox or radio button is not "successful".

您需要使用隐藏输入声明默认值.确保隐藏的输入位于复选框之前,因此如果选中此复选框,则由于名称相同,它将覆盖默认的隐藏输入:

You need to declare a default value with a hidden input. Make sure the hidden input comes before the checkbox so if the checkbox is checked it will override the default hidden input since the names are the same:

<input name="p-sis-0110-1" type="hidden" value="0">
<input name="p-sis-0110-1" type="checkbox" value="1">

要使用数组,您需要显式定义索引,以使它们相同:

To use an array you need to explicitly define the indexes so they are the same:

<input name="input[0]" type="hidden" value="0">
<input name="input[0]" type="checkbox" value="1">

这篇关于PHP:是否可以自动获取所有过帐的数据,并且取消选中多个复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆