我有一个这样的 HTML 架构:
链接:http: //i.stack.imgur.com/9RRpx.jpg
复选框名称:然后是 Lunes 列name = arrayLunes[]
、Martes 列name = arrayMartes[]
等...
首先,我想测试 Lunes 列表(星期一),如果我检查了first
和third
,则数组将具有only [0] and [1]
数组位置,但我想要例如:[0] = true, [1] = false, [2] = true, [3 .. x] = false
像这样的 PHP 代码,显然是行不通的,因为如果未选中复选框,则不会通过 POST 发送,所以它将是index offset error
for ($c = 0; $c < count($_POST['arrayLunes']); $c++)
echo ($_POST['arrayLunes'][$c] == 'on' ? "YES" : "NO");
结论:所以,现在,该$_POST['arrayLunes']
变量将只包含顺序checkbox checked
,我也需要未选中的,在他各自的位置。
我该怎么做或如何模拟它?
编辑
我的 HTML 代码是这样的
<div style="margin-left: 5px; padding: 5px;">
<input class="btnFranjas" type="button" value="- Quitar franja" onclick="removerFranjaCalendario();" />
<input class="btnFranjas" type="button" value="+ Añadir franja" onclick="addFranjaCalendario();" />
<input class="btnFranjas" type="button" value="Reestablecer" onclick="reestablecerFranja();" />
</div>
<form action="index.php?zona=plataforma&id=<?php echo $_GET['id']; ?>&acceso=<?php echo $_GET['acceso']; ?>" method="post">
<table id="tablaCalendario">
<thead>
<th>Horario</th>
<th>Lunes</th>
<th>Martes</th>
<th>Miércoles</th>
<th>Jueves</th>
<th>Viernes</th>
<th>Sábado</th>
<th>Domingo</th>
</thead>
<tbody>
<tr style="background: #E0E6F8;">
<td>
<table>
<tr>
<td><b>Inicio: </b></td>
<td>
Hora
<select id='arrayInicioHora[]' name='arrayInicioHora[]'>
<?php
for ($c = 0; $c < 24; $c++)
echo " <option value='" . $c . "'>".($c > 9 ? $c : "0" . $c)."</option>";
?>
</select>
</td>
<td>
Minuto
<select id='arrayInicioMinuto[]' name='arrayInicioMinuto[]'>
<?php
for ($c = 0; $c < 60; $c++)
echo "<option value='" . $c . "'>".($c > 9 ? $c : "0" . $c)."</option>";
?>
</select>
</td>
</tr>
<tr>
<td><b>Fin: </b></td>
<td>
Hora
<select id='arrayFinHora[]' name='arrayFinHora[]'>
<?php
for ($c = 0; $c < 24; $c++)
echo "<option value='" . $c . "'>".($c > 9 ? $c : "0" . $c)."</option>";
?>
</select>
</td>
<td>
Minuto
<select id='arrayFinMinuto[]' name='arrayFinMinuto[]'>
<?php
for ($c = 0; $c < 60; $c++)
echo " <option value='" . $c . "'>".($c > 9 ? $c : "0" . $c)."</option>";
?>
</select>
</td>
</tr>
</table>
</td>
<td align="center"><input type="checkbox" name="arrayLunes[]" id="arrayLunes[]" value="0" /> <input type="text" placeholder="Valor" name="arrayValorLunes[]" id="arrayValorLunes[]" style="width: 60px;" /></td>
<td align="center"><input type="checkbox" name="arrayMartes[]" id="arrayMartes[]" value="0" /> <input type="text" placeholder="Valor" name="arrayValorMartes[]" id="arrayValorMartes[]" style="width: 60px;" /></td>
<td align="center"><input type="checkbox" name="arrayMiercoles[]" id="arrayMiercoles[]" value="0" /> <input type="text" placeholder="Valor" name="arrayValorMiercoles[]" id="arrayValorMiercoles[]" style="width: 60px;" /></td>
<td align="center"><input type="checkbox" name="arrayJueves[]" id="arrayJueves[]" value="0" /> <input type="text" placeholder="Valor" name="arrayValorJueves[]" id="arrayValorJueves[]" style="width: 60px;" /></td>
<td align="center"><input type="checkbox" name="arrayViernes[]" id="arrayViernes[]" value="0" /> <input type="text" placeholder="Valor" name="arrayValorViernes[]" id="arrayValorViernes[]" style="width: 60px;" /></td>
<td align="center"><input type="checkbox" name="arraySabado[]" id="arraySabado[]" value="0" /> <input type="text" placeholder="Valor" name="arrayValorSabado[]" id="arrayValorSabado[]" style="width: 60px;" /></td>
<td align="center"><input type="checkbox" name="arrayDomingo[]" id="arrayDomingo[]" value="0" /> <input type="text" placeholder="Valor" name="arrayValorDomingo[]" id="arrayValorDomingo[]" style="width: 60px;" /></td>
</tr>
</tbody>
</table>
<input class="orangebutton" type="submit" name="enviarCalendario" id="enviarCalendario" onclick="return confirmacionAccion();" value="Enviar calendario" />
</form>
我的 javascript 用于此示例:http: //pastebin.com/eKFwMFvD