通过$ key的一部分选择$ _POST

时间:2018-07-02 14:51:43

标签: php arrays forms post

我有一个将数据发布到另一个php文件的表单。 通过日期,日期和加号“ -towards”形成了一些键。

表格/表格:     

                    <?php
                        for ($i = 1; $i < 8; $i++){

                            $d=strtotime("+".$i." Day");
                            if (date("l", $d) !== "Saturday" && date("l", $d) !== "Sunday" ){
                                $daydate = $dayOfWeek[date("l",$d)] .'_'. date("d", $d) .'_'.  $month[date("F",$d)];

                                echo "<tr>";
                                echo "<td><strong>". $dayOfWeek[date("l",$d)] .' '. date("d", $d) .' '.  $month[date("F",$d)] . "</strong></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "</tr>";

                                echo '<tr class="boardingTimeEarly">';
                                echo '<td style="padding-left: 30px; width: 24.5%; display: none">
                                        <input 
                                          class="form-check-input boardEarly1" 
                                          type="radio" 
                                          name="dates['.$daydate.'-to]" 
                                          value=""></input>
                                        <div class="time">0:00</div>
                                      </td>

                                    <td style="width: 24.5%; display: none">
                                        <input
                                          class="form-check-input boardEarly2" 
                                          type="radio" 
                                          name="dates['.$daydate.'-to]"
                                          value=""></input>
                                        <div class="time">0:00</div>
                                    </td>

                                    <td style="width: 24.5%; display: none">
                                        <input 
                                          class="form-check-input boardEarly3" 
                                          type="radio" 
                                          name="dates['.$daydate.'-to]"
                                          value="">
                                        </input>
                                        <div class="time">0:00</div>
                                    </td>

                                    <td style="width: 24.5%; display: none">
                                        <input 
                                          class="form-check-input boardEarly4" 
                                          type="radio" 
                                          name="dates['.$daydate.'-to]" 
                                          value="">
                                        </input>
                                        <div class="time">0:00</div>
                                    </td>   
                                </tr>';
                            }

                        }
                    ?>
            </table>
?>

我用JQUERY创建每个输入的值:

 $('#opstaphalte').change(function() { //OPTION IS SELECTED
$.ajax({
    type: 'POST', 
url: 'reserve.php', 
dataType: 'JSON',
data: {
        'station': this.value 
    },

    success: function(response){
        var to = 0;

        if(response['to']){ //CHECK IF RESPONSE CONTAINS INFO
            to = 1;
        }           

        for (var j=0; j<4; j++){

            var tdInput = $('.boardingTimeEarly').find('.boardEarly'+(j + 1));
            var td = $('.boardEarly').find('td');

            //HIDE DIV AND INPUT
            td.css('width', 'auto');
            tdInput.css('display', 'none');

            //Make TD Visible after selection choice
            if(td.css('display') == "none"){
                td.css('display', 'table-cell');
            }

            //TO DESTINATION ------------------------
            if(to){
                if(response['to'][j]){  //show content according to amount of times (max:4)
                    td.css('width', '25%');
                    tdInput.css('display', 'inline-block');
                    tdInput.attr('value', response['to'][j].slice(0,5));    
                    tdInput.next().html(response['to'][j].slice(0,5));
                }
            }
            else{
                //No BOARDINGTIMES KNOWN
                td.css('width', 'auto');
                td.css('display', 'table-cell');
                var noTimes = $('.boardEarly').find('.opstapOchtend1');
                noTimes.next().html("No boardingtimes.");
            }

        }

    } //end SUCCESS

  }); // END AJAX
});

当我尝试将所有选定的“对”时间放入POST数组中时。 我得到“ NUL”。

我的帖子摘要

array(5) {
 ["contact_name"]=>
  string(0) ""
 ["company"]=>
  string(0) ""
 ["email"]=>
  string(16) "test@gmail.com"
 ["boardingPlace"]=>
  string(1) "2"
 ["dates"]=>
  NULL
}

考虑到我对$ _POST键的看法,日期是不同的,我该如何选择将它们放入邮件中?

如何选择其中有日期的$ _POST? 我要在$ key中搜索日期,然后“朝着”或“向后”吗?

还是有更好的方法?

0 个答案:

没有答案