Php 如何打印选定的下拉列表值?

Php 如何打印选定的下拉列表值?,php,html,forms,Php,Html,Forms,我们有一个报价回复表,我们希望向客户显示此服务将在最短和最长时间内完成。为此,我们做了两个下拉列表 最小持续时间 最大持续时间 发送两个选定值时,如何在答案中显示 <form method="post" class="quotation-reply default-hidden" id="editquotationreply"> <div class="clearfix row input_fields_wrap"> <div class="col-

我们有一个报价回复表,我们希望向客户显示此服务将在最短和最长时间内完成。为此,我们做了两个下拉列表

  • 最小持续时间
  • 最大持续时间
  • 发送两个选定值时,如何在答案中显示

      <form method="post" class="quotation-reply default-hidden" id="editquotationreply">
      <div class="clearfix row input_fields_wrap">
        <div class="col-md-6">
            <div class="form-group">
    
    if($time_duration = 15){
                    $timeduration = array(15 => esc_html__('15 Mins', 'service-finder'),30 => esc_html__('30 Mins', 'service-finder'),45 => esc_html__('45 Mins', 'service-finder'),60 => esc_html__('1 Hr', 'service-finder'),75 => esc_html__('1 Hr 15 Mins', 'service-finder'),90 => esc_html__('1 Hr 30 Mins', 'service-finder'),105 => esc_html__('1 Hr 45 Mins', 'service-finder'),120 => esc_html__('2 Hrs', 'service-finder'),150 => esc_html__('2 Hrs 30 Mins', 'service-finder'),180 => esc_html__('3 Hrs', 'service-finder'),210 => esc_html__('3 Hr 30 Mins', 'service-finder'),240 => esc_html__('4 Hrs', 'service-finder'));
                }
                    ?>
    
    <select class="sf-select-box form-control sf-form-control" name="min_timeduration" data-live-search="true" title="<?php esc_html_e('Time Duration', 'service-finder'); ?>">
                    <option value=""><?php esc_html_e('Max Time Duration', 'service-finder'); ?></option>
                    <?php
                    if(!empty($timeduration)){
                        foreach($timeduration as $key => $value){
                            echo '<option value="'.esc_attr($key).'">'.esc_html($value).'</option>';    
                        }
                    }
                    ?>
                  </select>  </div>
                </div>
    
    
    如果($time\u duration=15){
    $timeduration=array(15=>esc\U html\uuuuuuu('15分钟','service finder')、30=>esc\U html\uuuuuuuuuuuuuu('30分钟','service finder')、45=>esc\U html\uuuuuuuuu('1小时','service finder')、75=>esc\uHTML\uuuuuuuuuuuuuuu('1小时15分钟','service finder')、90=>esc\uuuuuuuuuuuuuuuuuuuuuuuu('1小时30分钟','service finder')、105=>__('1小时45分钟','service finder'),120=>esc_html_uuuuuu('2小时','service finder'),150=>esc_html_uuuuuu('2小时30分钟','service finder'),180=>esc_html_uuuuuuuuu('3小时','service finder'),210=>esc_html_uuuuuuuuuuuu('3小时','service finder'),240=>esc_uHTML_uuuuuuuuuuuuuuuuuu;
    }
    ?>
    
    提交表单后是否重新加载页面,然后所选值应显示为已选?在这种情况下,您可以使用PHP的
    $\u SESSION
    变量存储所选的
    $key
    ,并在
    foreach
    循环中检查此变量,并将“selected”添加到相应的选项中

    session_start();
    if(!empty($_POST['min_timeduration'])) {
        $_SESSION['selected']  = $_POST['min_timeduration'];
    }
    $timeduration = [...];
    foreach($timeduration as $key => $value) {
        echo '<option value="' . esc_attr($key) .'"';
        if(!empty($_SESSION['selected']) && $_SESSION['selected'] == $key) {
            echo ' selected ';
        }
        echo '>'. esc_html($value) .'</option>';    
    }  
    
    session_start();
    如果(!空($\u POST['min\u timeduration'])){
    $_会话['selected']=$_POST['minu timeduration'];
    }
    $timeduration=[…];
    foreach($key=>$value的持续时间){
    echo'.esc_html($value)。'';
    }  
    
    最小时间代码在哪里?正如您所说,我们尝试了,但没有成功。显示错误。请向我解释正确代码的详细信息。是的,提交表单后重新加载页面。请查看屏幕截图:您在第二个屏幕截图中收到的错误消息是什么?它看起来对我来说不是有效代码(根据您的语法突出显示)。先生,我们正在查看此错误。(语法错误,意外的T_字符串)请帮助我们建立正确的代码。看起来您的整个HTML都在“”中进行了回显和封装。我正在使用相同的字符作为数组索引。请将封装更改为“”或将数组索引符号更改为“”“.提示:看看编辑器中的突出显示,它表明并非所有内容都正确标识为PHP。先生,我们不明白您在说什么。请向我解释代码示例。