在选择下拉列表中使用数组

时间:2018-12-02 12:44:26

标签: php

使用POST方法提交表单时获取未定义的项目。

<?php   
$reason = array(
    "Expected delivery date has changed and the product is arriving at a later date",
    "Product is being delivered to a wrong address(Customer’s mistake)",
    "Product is not required anymore.",
    "Cheaper alternative available for lesser price.",
    "I am not going to be available in town due to some urgent travel.",
    "Change in delivery address, non deliverable pincode."
);
?>
<select class="form-control" id="sel1" required>
     <option>Seclect reason</option>
     <?php
     foreach($reason as $item){
       echo '<option value="' . strtolower($item) .'">' . $item . '</option>';
      }
     ?> 
</select>
          <button type="submit" class="btn btn-primary" name="cancel">Submit</button>

1 个答案:

答案 0 :(得分:0)

您必须为name元素设置select属性,例如reasons,然后才能获得$_POST['reasons']之类的项目的值。例如:不再需要该产品。

NB 尝试使用较小的值作为您的option值,例如,使用$reason作为关联数组并将设置为选项的{{ 1}}和来选择内部文本;

value