0

我在表单中有输入

<form name="frmAdd" method="POST" action="/index.php?a=save">
Status : <input type="checkbox" id="status" name="chkActive" value="" ><label for="status">Active</label>
</form>

但是当我通过 $_POST['chkActive'] 调用它的值时,它在该页面上给出了相同的值。我是否检查了该值。

请告诉我我怎么知道这个复选框是否被选中(在 PHP 中)。

4

3 回答 3

2

如果您只使用一个复选框,您可以这样做:

<input type="checkbox" id="status" name="chkActive" value="1" >

在 PHP 中

if (isset($_POST['chkActive'])) {
   //its checked
}

但您需要确保在 HTML 中设置了一个值

于 2012-04-26T08:01:01.910 回答
0
<form name="frmAdd" method="POST" action="/index.php?a=save">
  Status : <input type="checkbox" id="status" name="chkActive" value="1" ><label      for="status">Active</label>
</form>

<?php if($_POST['chkActive']=='1'){
  echo "is Active";
}else{
  echo "not Active";
}

复选框仅在选中时传递值。

于 2012-04-26T08:01:15.020 回答
0

澄清它是如何工作的。

<input type="checkbox" id="status" name="chkActive"

如果未选中复选框(由用户选中),则不会向服务器发送任何内容。“chkActive”将不存在。所以我们使用 isset() 来检查它。

于 2012-04-26T08:12:24.553 回答