当我提交表单时,只有一个值来自多输入名称

时间:2016-12-17 15:42:14

标签: javascript php html

以下是我的代码示例:

<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);

但输出只是第一个输入值。我做错了什么?

因为在加载输入字段值得到但克隆字段值不能得到。

1 个答案:

答案 0 :(得分:1)

您只从表单中获取一个值的原因是您只是从表单中请求一个值。

#topLeft { position:relative!important; width:47.46%!important; top: 30px; left: 5%; margin:0px; float: left; padding:0px; display:inline-block; max-width: 485.984px; min-width: 450px; } #topLeftWebpart{ width:100%!important; } .image-area-left-top{ position:relative; float:left; width:20%!important; height:auto!important; } .image-area-left-top .image{ width:75%; height:75%; margin-top: 12.5%; margin-left: 12.5%; margin-bottom: 12.5%; margin-right: 12.5%;

您在此处请求表单中的单个对象。基本上你要问的形式是$my = $_REQUEST['dp_day'];的价值,但就是这样。如果您想从表单中获取更多变量,则必须请求另外请求。

例如,如果您想要dp_day,则需要再次提出请求:

dp_time