【发布时间】:2018-04-22 01:23:55
【问题描述】:
我想提交一个表单,在当前行复选框被选中时发布输入文本字段。
当我提交时,我得到了复选框的产品ID,但得到了所有的产品链接。我只想获取相应复选框的输入文本。
我该怎么做?
<form action="process.php" method="post">
<table>
<tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr><tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr><tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr><tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr><tr>
<td><input type="checkbox" name="productId[]" value="<?= $products->id; ?>" /> <input type="text" name="productLink[]" /></td>
</tr>
</table>
<input type="submit" name="formSubmit" value="Submit" />
</form>
【问题讨论】:
-
你不能。由于 procuctLink 是一个数组,您将获得所有这些。无论如何,您将收到表单内的所有内容。你只需要过滤/选择你需要的东西。您可以检查哪个复选框设置为true,然后获取相应的输入。
-
用相同的键链接它们 ->
name="productId[1]"/name="productLink[1]"。然后在发布时,您可以遍历复选框键以仅获取输入键值 -
我之前的答案可能应该是
<label> <input type="checkbox" name="productId[][<?= $products->id ?>]" value="<?= $products->link ?>" /> Product Name Goes Here </label>(请注意开头的额外数组以允许输入分组。)
标签: php html codeigniter