PHP将Checkbox值和下拉值传递给Next POST [英] PHP Pass Checkbox values and dropdown values to Next Page POST

查看:87
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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