2016-12-17 51 views
0

這裏給我提交表單只有一個值是我的代碼示例:從多輸入名稱

<div class="panel panel-default"> <!--Day Plan--> 

     <div class="panel-heading"> 
      <h4 class="panel-title"> <a class=" accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#collapseFour"> ITINERARY </a> </h4> 
     </div> 
     <div id="collapseFour" class="panel-collapse collapse "> 
      <div class="panel-body dayplan"> <!--Day Plan--> 

      <div class="control-group" id="fields"> 
       <label class="control-label" for="field1">Please add Day Plan </label> 
       <div class="controls_day_plan"> 
        <div class="entry_day_plan input-group col-sm-12 col-xs-12 "> 
        <div class="form-group col-sm-2 col-xs-12"> 
         <label for="exampleInputnumber"> Select Day </label> 
         <select class="form_line_only form-control" name="dp_day[]" id="select_time"> 
         <option > 1 </option> 
         <option > 2 </option> 
         <option > 3 </option> 
         <option > 4 </option> 
         <option > 5 </option> 
         <option > 6 </option> 
         <option > 7 </option> 
         </select> 
        </div> 
        <div class="form-group col-sm-2 col-xs-12"> 
         <label for="exampleInputnumber"> Select Time </label> 
         <select class="form_line_only form-control" name="dp_time[]" id="select_time"> 
         <option selected> Full Day </option> 
         <option > Morning </option> 
         <option > After Noon </option> 
         <option > Evening </option> 
         <option > Night </option> 
         </select> 
        </div> 
        <div class="form-group col-sm-7 col-xs-12"> 
         <label for="exampleInputnumber"> Please Select Place </label> 
         <!--<input type="text" name="dp_place[]" class="form-control form_line_only" id="select_place" placeholder="Please Select Place">--> 
         <input type="text" class="className form-control form_line_only" name="ex_name[]" id="ex_name" placeholder="Enter Add Excursion"> 
        </div> 
        <span class="input-group-btn day_plan pull-left"> 
        <button class="btn btn-success btn-add add_col" type="button"> <span class="glyphicon glyphicon-plus"></span> </button> 
        </span> </div> 

       <br> 
       <small>Press <span class="glyphicon glyphicon-plus gs"></span> to add another Day Plan)</small> </div> 
      </div> 
      </div> 
      <!--/.Day Plan--> 

     </div> 
     </div> 

的JavaScript:

$(function() 

{ 

    $("body").on('click', '.btn-add', function(e) 

    { 

     e.preventDefault(); 



     var controlForm = $('.controls_day_plan:first'), 

      currentEntry = $(this).parents('.entry_day_plan:first'), 

      newEntry = $(currentEntry.clone()).appendTo(controlForm); 



     newEntry.find('input').val(''); 

     controlForm.find('.entry_day_plan:not(:last) .btn-add') 

      .removeClass('btn-add').addClass('btn-remove') 

      .removeClass('btn-success').addClass('btn-danger') 

      .html('<span class="glyphicon glyphicon-minus"></span>'); 

    }).on('click', '.btn-remove', function(e) 

    { 

     $(this).parents('.entry_day_plan:first').remove(); 



     e.preventDefault(); 

     return false; 

    }); 

}); 

每當我只提交這份表格給我第一個輸入值。

PHP代碼

$my = $_REQUEST['dp_day']; 
print_r($my); 

但輸出僅是第一輸入值。我究竟做錯了什麼?

由於負載輸入字段值得到但克隆字段值不能得到。

+0

你應該看看這篇文章:http://stackoverflow.com/help/how-to-ask –

回答

1

您只從表單獲取一個值的原因是您只需從表單中請求一個值。

$my = $_REQUEST['dp_day'];

這裏您要求從形式的單個對象。基本上所有你問的表格是dp_day的價值,但就是這樣。如果你想從表單中獲得更多的變量,你將不得不請求另一個請求。

例如,如果你想dp_time你將不得不作出另一個請求它像這樣:

$time = $_REQUEST['dp_time'];