[英]when I submit form only one value given from multi input name
Here is a sample of my code: 这是我的代码示例:
<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: 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;
});
});
Whenever I submit this form it only give me first input value. 每当我提交此表格时,它只会给我第一个输入值。
PHP Code PHP代码
$my = $_REQUEST['dp_day'];
print_r($my);
But the output is only first input value. 但是输出只是第一个输入值。 What am I doing wrong?
我究竟做错了什么?
Because on load input field value get but clone field value cant get. 因为在加载时输入字段值获取但克隆字段值无法获取。
The reason why you are only getting one value from your form is because you are only requesting one value from your form. 之所以只从表单中获取一个值,是因为您仅从表单中请求了一个值。
$my = $_REQUEST['dp_day'];
Here you are requesting a single object from the form. 在这里,您从表单中请求一个对象。 Basically all you are asking the form for is the value of
dp_day
but that is it. 基本上,您要求表单提供的只是
dp_day
的值, dp_day
此而已。 If you want to get more variables from the form you would have to request make another request. 如果要从表单中获取更多变量,则必须请求再次发出请求。
For example if you wanted dp_time
you would have to make another request for it like so: 例如,如果您想要
dp_time
,则必须再次发出请求,如下所示:
$time = $_REQUEST['dp_time'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.