复选框数组返回NULL [英] Checkbox array returning NULL
问题描述
我希望在我正在开发的结算系统中有一个批量删除功能,但当复选框 var_dump
ed时,会在检查时产生一个NULL值 。
I want a batch deletion feature in the billing system I am developing, however the checkboxes, when var_dump
ed yields a NULL value when checked.
以下是我的标记(已编辑):
Here is my markup (edited):
<form method="post" name="form-countries-del">
<div id="deleteBox">
<span class="middleAlign"><b>No. of Records:</b> <span class="red"><?= $qtotal; ?></span></span>
<span class="rightAlign">
<input type="submit" value="Delete" name="submit-countries-del" class="del-submit" />
</span>
</div>
<table border="1" id="src-table">
<tr class="header">
<td><input type="checkbox" id="toggleChecks"></td>
<td class="_hide">CountryID</td>
<td>Country Code</td>
<td>Country Name</td>
<td>Telco Rate</td>
</tr>
<?php while($row = $pdo->fetch()) : ?>
<tr class="<?=($c++%2==1) ? 'even' : 'odd' ?>" title="Double click to edit">
<td><input type="checkbox" name="toDelete[]" id="toDelete[]" class="toDelete" value="<?= $row['CountryID']; ?>" /></td>
<td class="_hide"><?= $row['CountryID']; ?></td>
<td><?= highlight($_POST['search'], $row['CountryCode']); ?></td>
<td><?= highlight($_POST['search'], $row['CountryName']); ?></td>
<td><?= $row['Trate']; ?></td>
</tr>
<?php endwhile; ?>
</table>
</form>
生成的表单(Google Chrome)如下所示:
不幸的是它只产生NULL。我想知道我错过了什么。我一直在浏览大量关于我的问题的类似文章,但迄今为止还没有工作。
The generated form (Google Chrome) is like this:
It just yields NULL unfortunately. I wonder what I've been missing. I've been scanning a whole lot of similar articles regarding my problem but none has worked thus far.
我希望你们的人能帮助我!
干杯!
I hope you folks can help me! Cheers!
推荐答案
一些MVC框架混淆了诸如POST之类的请求变量。这可能是你的情况。由于您的提交按钮发布无误,因此可能只是POST数组的问题。试试这个来解决这个问题。
Some MVC frameworks mess around with the request variables such as POST. It's possible this is the case with you. As your submit button is posting ok, it could be just a problem with POSTing arrays. Try this to get around that problem.
<input type="checkbox" name="toDelete-<?= $row['CountryID']; ?>" id="toDelete[]" class="toDelete" value="<?= $row['CountryID']; ?>" /></td>
<td class="_hide"><?= $row['CountryID']; ?>
您可以像这样访问值:
$toDelete = array();
foreach($_POST as $p){
$ex = explode('-',$p);
if($ex[0]=='toDelete'){
$toDelete[] = $ex[1];
}
}
这篇关于复选框数组返回NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!