PHP将Checkbox值和下拉值传递给Next POST

编程入门 行业动态 更新时间:2024-10-28 20:29:07
本文介绍了PHP将Checkbox值和下拉值传递给Next POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用PHP/MYSQL解决方案,其中有一些带有复选框的国家/地区列表.某些国家/地区有一个称为实体"的实体,它是一个下拉菜单,其中将微",小",大"显示为一个下拉菜单.此实体下拉列表仅在某些国家/地区出现.我能够将复选框的选中值传递给下一页.但是我还需要传递下拉菜单中选择的实体的值.我无法做到这一点.我的代码,即张贴在下面.在这里,我还需要将下拉列表的值(选择-entity_selected)也传递给下一页:

Iam trying a solution in PHP/MYSQL where in there is a some country list with a checkbox. Certain countries have something called entities which is a drop down which shows Micro, Small, Large as a dropdown. This entity dropdown appears for certain countries only. I am able to pass the checkbox checked values to next page. But i need to pass the value of the entity selected in the drop down also. Iam not able to acheieve that. My code ie posted below. Here i need to pass the value of the drop down (select - entity_selected) also to next page:

<?php echo '<table border="1">'; while($row1 = mysqli_fetch_array($result_country)) { $country1 = $row1["country"]; $entity1 = $row1["entity"]; echo '<tr>'; ?> <td><input name="check_list[]" type="checkbox" value="<?php echo $country1;?>"> <?php echo $country1;?></td> <td> <?php if($entity1 == 'Yes'){ ?> <select class="form-control selectpicker" name="entity_selected"> <option value="Micro">Micro</option> <option value="Small">Small</option> <option value="Large">Large</option> </select> <?php } ?> </td> <?php echo '</tr>'; } ?> </table>

下面的页面代码位于下面,以获取选中的国家/地区复选框.

The Next page code is below to get the check box selected countries.

if(!empty($_POST['check_list'])) { foreach($_POST['check_list'] as $check) { echo $check; } }

我如何在这里获得下拉值?我得到复选框(正确的国家/地区值).有人可以帮我这个忙吗?

How can i get the drop down values here? iam getting the checkbox (countries values correctly). Can anyone pls help me on this pls?

推荐答案

<form method="POST" action="nextpage.php"> <table border="1"> <?php $i = 0; while($row1 = mysqli_fetch_array($result_country)) { $country1 = $row1['country']; $entity1 = $row1['entity']; echo "<tr>"; ?> <td> <input name="check_list<?=$i ?>" type="checkbox" value="<?php echo $country1;?>"> <?php echo $country1;?> </td> <td> <?php if($entity1=="Yes") { ?> <select class="form-control selectpicker" name="entity_selected<?=$i ?>"> <option value="Micro">Micro</option> <option value="Small">Small</option> <option value="Large">Large</option> </select> <?php }; ?> </td> <?php $i++; echo "</tr>"; }; ?> </table> </form>

nextpage.php:

nextpage.php:

<?php $entities = $checklist = []; foreach($_POST as $k => $v) { if(preg_match("/^checklist(\d+)$/", $k, $matches)) $checklist[intval($matches[0])] = $v; unset($matches); if(preg_match("/^entity_selected(\d+)$/", $k, $matches)) $entities[intval($matches[0])] = $v; }; ?>

更多推荐

PHP将Checkbox值和下拉值传递给Next POST

本文发布于:2023-10-29 08:44:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539241.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   Checkbox   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!