我的表格摘录如下:
// If logged in shows this box (it's backed behind a include php file that makes the login check
<form action="./saveList.php" method="post" id="ListaComprasForm">
<div class="submitButtonEncap">
<button type="submit" method="POST" name="submitButton" class="btn btn-primary roundedBorder" form="ListaComprasForm" value="submit">
<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span> Save List
</button>
</div>
<input type="text" id="Limpeza0" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_0" name="L_chckb_[]" value="check"/>
<input type="text" id="Limpeza1" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_1" name="L_chckb_[]" value="check"/>
<input type="text" id="Limpeza2" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_2" name="L_chckb_[]" value="check"/>
<input type="text" id="Limpeza3" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_3" name="L_chckb_[]" value="check"/>
<input type="text" id="Limpeza4" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_4" name="L_chckb_[]" value="check"/>
<input type="text" id="Limpeza5" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_5" name="L_chckb_[]" value="check"/>
<input type="text" id="Limpeza6" name="Limpeza[]" class="listInput" autocomplete="off" maxlength="50">
<input type="checkbox" class="x" id="L_chck_6" name="L_chckb_[]" value="check"/>
</form>
此表单在提交时将提交给数据库是否已填充复选框和TextBox字段已填写或未填写。选中或未选中的复选框,他将分别通过一些排序代码为文本框提交Y
和N
或nullo
,如下所示:
if (isset($_POST['submitButton'])){
$L_chck[] = array();
$H_chck[] = array();
$V_chck[] = array();
$F_chck[] = array();
$Cong_chck[] = array();
$Cons_chck[] = array();
$Outros_chck[] = array();
$Outros = array();
for ($counter = 0; $counter <= 6; $counter++){
$L_chck[$counter] = (isset($_POST['L_checkb_'.$counter]) ? 'Y' : 'N');
$H_chck[$counter] = (isset($_POST['H_checkb_'.$counter]) ? 'Y' : 'N');
$V_chck[$counter] = (isset($_POST['V_chckb_'.$counter]) ? 'Y' : 'N');
$F_chck[$counter] = (isset($_POST['F_chckb_'.$counter]) ? 'Y' : 'N');
$Cong_chck[$counter] = (isset($_POST['Cong_chckb_'.$counter]) ? 'Y' : 'N');
$Cons_chck[$counter] = (isset($_POST['Cons_chckb_'.$counter]) ? 'Y' : 'N');
$Outros_chck[$counter] = (isset($_POST['Outros_chckb_'.$counter]) ? 'Y' : 'N');
if (empty($_POST['Outros'.$counter])) {
$Outros[$counter] = $_POST['Outros'.$counter] = 'nullo';
} else {
$Outros[$counter] = $_POST['Outros'.$counter];
}
}
for ($i=0; $i <= 4; $i++) {
/*if ((isset($_POST['Limpeza'.$i])) == false) {*/
if (empty($_POST['Limpeza'.$i])) {
$Limpeza[$i] = $_POST['Limpeza'.$i] = 'nullo';
} else {
$Limpeza[$i] = $_POST['Limpeza'.$i];
}
if (empty($_POST['Higiene'.$i])) {
$Higiene[$i] = $_POST['Higiene'.$i] = 'nullo';
} else {
$Higiene[$i] = $_POST['Higiene'.$i];
}
if (empty($_POST['Vegetais'.$i])) {
$Vegetais[$i] = $_POST['Vegetais'.$i] = 'nullo';
} else {
$Vegetais[$i] = $_POST['Vegetais'.$i];
}
if (empty($_POST['Fruta'.$i])) {
$Fruta[$i] = $_POST['Fruta'.$i] = 'nullo';
} else {
$Fruta[$i] = $_POST['Fruta'.$i];
}
if (empty($_POST['Congelados'.$i])) {
$Congelados[$i] = $_POST['Congelados'.$i] = 'nullo';
} else {
$Congelados[$i] = $_POST['Congelados'.$i];
}
if (empty($_POST['Conservas'.$i])) {
$Conservas[$i] = $_POST['Conservas'.$i] = 'nullo';
} else {
$Conservas[$i] = $_POST['Conservas'.$i];
}
}
然后将这些数据作为参数传递给要序列化的函数并发送到DB字段,所有这些都是varchar(255):
savingListData($L_chck, $H_chck, $V_chck, $F_chck, $Cong_chck, $Cons_chck, $Outros_chck, $Limpeza, $Higiene, $Vegetais, $Fruta, $Congelados, $Conservas, $Outros);
到目前为止,每一条数据,无论是否经过检查/填充,都会将数据转换为空值。如果是复选框N
,则为文本框nullo
。
我被引导相信排序中出现了问题,但我很困惑,无法弄清楚原因。真的很感激一些帮助!!
编辑:以缩短的方式添加更多表单。 (这是一个很大的形式!)
答案 0 :(得分:1)
我认为您正在尝试使用错误的名称检索它。其L_chckb_[]
<input type="checkbox" class="x" id="L_chck_0" name="L_chckb_[]" value="check"/>
所以你需要在名称键之外使用循环计数器,如下所示:
$L_chck[$counter] = (isset($_POST['L_chckb_'][$counter]) ? 'Y' : 'N');
问题是:标记中的name属性为L_chckb_
,但您尝试通过L_checkb_
检索它,这就是问题所在。
由于L_checkb_
未设置,因此它会为您提供N
。