PHP - Codeigniter并非所有表单元素都通过post方法发送到控制器

时间:2015-09-27 10:57:04

标签: php html codeigniter post

我有一个类似下面代码的表单,当单击提交按钮时,并不是表单的所有元素都被发送到Codeigniter的控制器,尤其是txtStartLocationtxtEndLocation。我清楚地定义了两个元素的名称。 这是我在var_dump帖子元素

时得到的结果
array(8) { 
["txtStartDate"]=> string(10) "2015-09-29" 
["txtEndDate"]=> string(10) "2015-09-30" 
["txtStartTime"]=> string(4) "8:45" 
["txtEndTime"]=> string(5) "14:45" 
["txtStartLocation_Coordinates"]=> string(32) "(36.106965, -112.11299700000001)" 
["txtEndLocation_Coordinates"]=> string(23) "(37.559152, 126.983967)"
["txtTotalDetail"]=> string(1) "0" 
["txtNoOfDays"]=> string(1) "2" }`

表单视图

 <form name="frm_RRequest" id="frm_RRequest" action="<?php echo site_url('user/add_recommendation_request/'); ?>" method="post">                      
                    <tbody>
                      <tr>
                        <td class="col-left">Date</td>
                        <td class="col-middle"><input class="datepicker" type="text" name="txtStartDate" id="txtStartDate" class="datepicker" placeholder="Click to select a start date.."></td>
                        <td class="col-middle"><input class="datepicker" type="text" name="txtEndDate" id="txtEndDate" class="datepicker" placeholder="Click to select a end date.."></td>
                        <td class="col-right"><div class="error" id="error_date">&nbsp;</div></td>
                      </tr>
                      <tr>
                        <td class="col-left">Travel time</td>
                        <td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtStartTime" id="txtStartTime" placeholder="Click to select start time.." data-default-time="false"></td>
                        <td class="col-middle"><input type="text" class="ptTimeSelect input" name="txtEndTime" id="txtEndTime" placeholder="Click to select end time.." data-default-time="false"></td>
                        <td class="col-right"><div class="error" id="error_time">&nbsp;</div></td>
                      </tr>
                      <tr>
                        <td class="col-left">Location</td>
                        <td class="col-middle-2"><input type="text" class="inputWithImge" name="txtStartLocation" id="txtStartLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a start point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_start" value="StartLocation"/></td>
                        <td class="col-middle-2"><input type="text" class="inputWithImge" name="txtEndLocation" id="txtEndLocation" onmouseover="display_text(this)" placeholder="Click the icon to select a end point"/><img src="<?php echo base_url('assets/images/search_icon.png'); ?>" class="location-icon" title="Click to show map" name="location-icon_end" value="EndLocation" /></td>
                        <td class="col-right"><div class="error" id="error_location">&nbsp;</div></td>
                      </tr>
                    </tbody>
                  </table>
                </div>
                <input type="hidden" name="txtStartLocation_Coordinates" id="txtStartLocation_Coordinates">
                <input type="hidden" name="txtEndLocation_Coordinates" id="txtEndLocation_Coordinates">
                <div><input type="button" class="button" id="btnGo" name="btnGo" value="Input detail" />&nbsp; <span> << click this button if the travel time and location(s) are different for each day</span></div>
                <div id="detail"> 

                </div>
                <input type="hidden" name="txtTotalDetail" id="txtTotalDetail">
                <input type="hidden" name="txtNoOfDays" id="txtNoOfDays">
                <div>&nbsp;</div>
                <div><input type="button" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" /></div>
</form>

1 个答案:

答案 0 :(得分:0)

尝试使用这样的打开/关闭表单:

<?php echo form_open("controller/function"); ?>

<?php echo form_close(); ?>

然后改变

<input type="button" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" />

<input type="submit" id="btn_SaveDetail" name="btn_SaveDetail" class="button" value="Save" />