How to send checkbox state through form in a table

2019-08-10 14:54发布

Below form contains a table with checkboxes as a input type when I do a var_dump of _POST the values of each check box doesn't come through

<form method="post" action="index.php?option=com_content&view=article&id=3" name="details" >
        <div id="table_container">   
        <table class="z">
            <thead>
                <tr>
                    <th>Select</th>
                    <th>Last Name</th>
                    <th>First Name</th>
                    <th>Street Num</th>
                    <th>Street Name</th>
                    <th>City</th>
                    <th>State</th>
                    <th>Zip</th>
                    <th>Phone</th>
                </tr>
            </thead>
            <tbody>
                <?
                while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                    ?>  
                    <tr>
                        <td style="text-align: center; vertical-align: middle;">
                            <input type="checkbox" name="<?echo $row['UUID'];?>">    
                        </td>
                        <td><?echo $row['last_name'];?></td>
                        <td><?echo $row['first_name'];?></td>
                        <td><?echo $row['street_num'];?></td>
                        <td><?echo $row['street_name'];?></td>
                        <td><?echo $row['city'];?></td>
                        <td><?echo $row['state'];?></td>
                        <td><?echo $row['zip'];?></td>
                        <td><?echo $row['phone'];?></td>                        
                    </tr>
                    <?                  
                }
                ?>
            </tbody>
        </table>
        </div>
        <input type="hidden" id="type" name="type" value="4">
            <input type="submit" value="Place On Hold">
        </form>

2条回答
老娘就宠你
2楼-- · 2019-08-10 15:04

Suppose this is your checkbox: <input type="checkbox" name="uid" value="some_value">

you can use below code to check whether this checkbox is checked or not:

 <?php
  echo (isset($_POST['uid'])?$_POST['uid']:'');
 ?>

isset($_POST['uid']) will check whether its checked or not, and therefore $_POST['uid'] will return its value if checked.

查看更多
Emotional °昔
3楼-- · 2019-08-10 15:13

So I think what you want to do is this though. If I understand it correctly.

<input type="checkbox" name="UUID[]" value="<?echo $row['UUID'];?>">

Now when you post the page you will have an array called UUID in the POST with each UUID selected.

查看更多
登录 后发表回答