从多个复选框获取$ _POST [英] Get $_POST from multiple checkboxes

查看:95
本文介绍了从多个复选框获取$ _POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有1个表格,其中有多个复选框(每个都有代码):

I have 1 form in with multiple checkboxes in it (each with the code):

<input type="checkbox" name="check_list" value="<? echo $row['Report ID'] ?>">

其中 $ row ['Report ID'] 是数据库中的主键 - 每个值都不同。

Where $row['Report ID'] is a primary key in a database -so each value is different.

我如何能够知道哪些复选框已被选中? (可能是多个)

How would I be able to tell which checkboxes have been checked? (Maybe multiple)

(在上下文中:)它对于收件箱系统,我有一个按钮下面,我想要(当点击)删除所有邮件 $ row ['Report ID'] )其中有复选框的选中...

(In context:) Its for an inbox system and I have a button below that I want (when clicked) to delete all messages (id's of: $row['Report ID']) which have the checkbox's checked...

谢谢alot ...

Thanks alot...

推荐答案

check_list [] 的形式,您将能够访问所有复选框作为数组( $ _ POST ['check_list'] [] )。

Set the name in the form to check_list[] and you will be able to access all the checkboxes as an array($_POST['check_list'][]).

这里有一个请求的示例:

Here's a little sample as requested:

<form action="test.php" method="post">
<input type="checkbox" name="check_list[]" value="value 1">
<input type="checkbox" name="check_list[]" value="value 2">
<input type="checkbox" name="check_list[]" value="value 3">
<input type="checkbox" name="check_list[]" value="value 4">
<input type="checkbox" name="check_list[]" value="value 5">
<input type="submit" />
</form>
<?php
if(!empty($_POST['check_list'])) {
    foreach($_POST['check_list'] as $check) {
            echo $check; //echoes the value set in the HTML form for each checked checkbox.
                         //so, if I were to check 1, 3, and 5 it would echo value 1, value 3, value 5.
                         //in your case, it would echo whatever $row['Report ID'] is equivalent to.
    }
}
?>

这篇关于从多个复选框获取$ _POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆