如何使用复选框正确处理HTML,CSS和PHP形式的URL?

时间:2018-12-20 03:56:53

标签: php html css ajax

我在代码方面遇到麻烦,尤其是在表单方面。这是我的HTML代码。

<form action="index.php/homepage/deleteSelected" method="POST">
                            <input type="submit" value="Delete Selected">
                        <table align="center">
                            <thead>
                                <!-- <th>Action</th> -->
                                <th>Selection</th>
                                <th>ID</th>
                                <th>First Name</th>
                                <th>Last Name</th>
                                <th>Date Created</th>
                                <th>Options</th>
                            </thead>
                            <!-- CODE HERE -->
                    <?php $counter = 0; ?>
                    <?php foreach ($student_records as $row){?>
                        <?php if(($counter % 2) == 0){?>
                            <tbody class='even'>
                                <td><input type="checkbox" name="checklist[]" value="<?php echo $row->id;?>"></td>
                                <td><?php echo $row->id;?></td>
                                <td><?php echo $row->firstname;?></td>
                                <td><?php echo $row->lastname;?></td>
                                <td><?php echo $row->dateCreated;?></td>
                                <td>
                                    <a href='index.php/homepage/toEditStudent?id=<?php echo $row->id; ?>'><button class="btn btn-warning">Edit</button></a>
                                    <a href='index.php/homepage/deleteStudent?id=<?php echo $row->id; ?>'><button class="btn btn-danger">Delete</button></a>
                                </td>
                            </tbody>
                        <?php }else{?>
                            <tbody class='odd'>
                                <td><input type="checkbox" name="checklist[]" value="<?php echo $row->id;?>"></td>
                                <td><?php echo $row->id;?></td>
                                <td><?php echo $row->firstname;?></td>
                                <td><?php echo $row->lastname;?></td>
                                <td><?php echo $row->dateCreated;?></td>
                                <td>
                                    <a href='index.php/homepage/toEditStudent?id=<?php echo $row->id; ?>'><button class="btn btn-warning">Edit</button></a>
                                    <a href='index.php/homepage/deleteStudent?id=<?php echo $row->id; ?>'><button class="btn btn-danger">Delete</button></a>
                                </td>
                            </tbody>
                        <!-- END CONDITION -->
                        <?php }?>
                    <?php $counter++; ?>
                    <!-- END FOREACH -->
                    <?php }?>
                        </form>

每次我单击编辑按钮时,表单都会收到它。它必须转到index.php / homepage / toEditStudent而不是index.php / homepage / deleteSelected。任何建议将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

  

每次我单击编辑按钮时,表单都会收到它。它必须转到index.php / homepage / toEditStudent而不是index.php / homepage / deleteSelected。

您表单的action属性是index.php/homepage/deleteSelected

您需要将操作更改为index.php/homepage/toEditStudent

示例:

<form action="index.php/homepage/toEditStudent" method="POST">