简体   繁体   English

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

[英]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.

相关问题 当我提交表单时,如何在 jquery 中仅设置一个选项选择多 select - How to set only one option in jquery chosen multi select when I submit the form 当用户点击输入只有一个输入的表单时,请避免“提交” - avoid “submit” when user hits enter in form with only one input 可能的Javascript从多个等名输入中提交一个值? - Possible Javascript submit one value from multiple equal name input? 当我提交表单以防信息错误时,我只想在输入下显示一条错误消息,如何在此处进行操作? - when i submit my form in case the information are wrong i would like to show only ONE error message under the input , how to do it there? 仅在输入值更改时提交表单 - Submit form only if value of input change 仅当我从表单提交时才呈现一个React组件 - Only render a react component when I on submit from a form 仅从angularjs表单中提交检查值 - submit only checked value from form in angularjs 如何使用Enter键将项目添加到输入中,并且仅在单击按钮时才提交表单? - How can I add items to an input using the enter key and only submit the form when i click a button? 我用 javascript 设置输入标签的值,当提交表单时,php 中的值未定义 - I set value of an input tag with javascript and when submit the form, the value is undefined in php 如果用户专注于登录输入,如何在输入密钥时提交表单? - How do I get the form to submit on enter key only when user has focus on login input?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM