douqian5553 2018-04-16 09:25
浏览 55
已采纳

如何在PHP中获取值中的选定选项

Please guide me to get the selected option in a drop-down to the PHP variable

<div class="form-group">
    <label class="control-label" for="input-order-type"><?php echo $entry_order_type; ?></label>
    <select name="filter_order_type" id="input-order-type" class="form-control">
      <option value=""></option>
      <option value="<?php echo $filter_order_type; ?>">FB Orders</option>
      <option value="<?php echo $filter_order_type; ?>">Direct Orders</option>
      <option value="<?php echo $filter_order_type; ?>">Khathija's Orders</option>
      <option value="<?php echo $filter_order_type; ?>">Ameer's Orders</option>
      <option value="<?php echo $filter_order_type; ?>">Saheed's Orders</option>
      <option value="<?php echo $filter_order_type; ?>">Nada's Orders</option>
      <option value="<?php echo $filter_order_type; ?>">Henath's Orders</option>
      <option value="<?php echo $filter_order_type; ?>">Noha's Orders</option>
    </select>
    <?php echo $filter_order_type; ?>
</div>

I need the selected value to be assigned in $filter_order_type

  • 写回答

3条回答 默认 最新

  • dongzhuonao8429 2018-04-16 09:48
    关注

    I have used a form to submit what the user has selected. When the user submits the form the selected value will be posted and taken into the variable $entry_order_type. I think this is what you are expecting. Hope it helps. :)

    <?php
    $entry_order_type ="Select order type from the list and press the submit button";
    if(isset($_POST['filter_order_type'])){
       $entry_order_type = $_POST['filter_order_type'];  // Storing Selected Value In Variable
    }
    ?>
    <form action="#" method="post">
    <div class="form-group">
        <label class="control-label" for="input-order-type"><?php echo $entry_order_type; ?></label>
    
        <select name="filter_order_type" id="input-order-type" class="form-control">
    
          <option value=""></option>
    
          <option value="FB Orders" <?php if($entry_order_type=="FB Orders"){echo "selected";} ?> >FB Orders</option>
          <option value="Direct Orders" <?php if($entry_order_type=="Direct Orders"){echo "selected";} ?> >Direct Orders</option>
          <option value="Khathija's Orders" <?php if($entry_order_type=="Khathija's Orders"){echo "selected";} ?> >Khathija's Orders</option>
          <option value="Ameer's Orders" <?php if($entry_order_type=="Ameer's Orders"){echo "selected";} ?> >Ameer's Orders</option>
          <option value="Saheed's Orders" <?php if($entry_order_type=="Saheed's Orders"){echo "selected";} ?> >Saheed's Orders</option>
          <option value= "Nada's Orders" <?php if($entry_order_type=="Nada's Orders"){echo "selected";} ?> >Nada's Orders</option>
          <option value="Henath's Orders" <?php if($entry_order_type=="Henath's Orders"){echo "selected";} ?> >Henath's Orders</option>
          <option value="Noha's Orders" <?php if($entry_order_type=="Noha's Orders"){echo "selected";} ?> >Noha's Orders</option>
        </select>
        <input type="submit" name="submit" value="Get Selected Values" />
    
    </div>
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀