简体   繁体   English

有没有其他方法可以提交我动态添加的输入字段?

[英]is there any other way to submit my dynamically added input fields?

i have tried to create form input fields dynamically and i succeeded but when all other fields are being submitted, only the dynamically created fields are not please help out.. thanks..我尝试动态创建表单输入字段,我成功了,但是当提交所有其他字段时,只有动态创建的字段不是请帮忙...谢谢...

my javascript is working fine, its creating the fileds just fine inside the modal.. the problem is when i am submitting it only the dynamically added fields are not submitted..我的 javascript 工作正常,它在模态内创建文件就好了.. 问题是当我提交它时,只有动态添加的字段没有提交..

<form action='<?php echo $_SERVER['PHP_SELF'];?>' method="post"> 
 
 <div class="col-md-6">
     <div class="form-group">
      <h6> Contact person in case of emergency</h6
      <input class="form-control" placeholder="Contact person" required=""  pattern="([A-Z][a-z]*\s*[A-Z]*[a-z]*\s*[0-9]*)" title="Alphbetical characters only, capitalize first letter, full name then phone number" value="<?php echo $info[0]['contactperson'];?>" name="contactperson" type="text">
     </div>
    </div>
    
      
       
    
    <input class="form-control" hidden placeholder="familymembers"  id="fm" value="<?php echo $info[0]['familymembers'];?>"  name="familymembers" type="number">
        
      <div class="col-md-6">
        <div class="form-group">
            <h6>&nbsp;</h6>
              <a href="" data-toggle="modal" data-target="#seefmlist"><button class="btn btn-success">Edit Family Members List</button></a>
          </div>
        </div>
    
    //this is a script to add new input fields daynamically
    
    
     
    
    <script type="text/javascript">
          function getfmembers(){
          var fn=document.getElementById('fm').value;
             
          for (var i = 0; i < 1; i++) {
          document.getElementById('fm').value++;
          k=document.getElementById('fm').value;
         var btn='<div class="form-group"><input class="form-control" name="fmlis" placeholder="Name of the family member" id="'+k+'"  type="text"></div>';
    
             $("#after").after(btn);
             alert(document.getElementById(k).name);
    
             } 
              }
     function removefmembers(){
       var fn=document.getElementById('fm').value;
    
          $("input").remove("#"+fn); 
           document.getElementById('fm').value--;
        }
    
        </script>
    // this is the modal to submit the inputs and its inside the form tag
    <div class="modal fade" id="seefmlist" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Edit Family Members List</h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="row">
              <div class="col-md-3">
                <span onclick="getfmembers()" class="btn btn-sm btn-success">Add Member</span>
              </div>
              <div class="col-md-3">
                  <span onclick="removefmembers()" class="btn btn-sm btn-danger">Delete Last Member</span>
              </div>
            </div>
            <br>
        
            <div id="after">
            <?php
     $flist=explode(",",$info[0]['familylist']);
      if (count($flist)>1) {
      for ($qq=0; $qq < count($flist)-1 ; $qq++) { 
        echo '<div class="form-group"><input class="form-control" id="'.($qq+1).'"  value="'.$flist[$qq+1].'"  name="fmlist'.($qq+1).'" type="text"></div>';
                           
                            }
                            }
    
    
              ?>
    
         
              </div>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-primary">Update changes</button>
          </div>
        </div>
      </div>
    </div>
     
    </div>
    
    <div class="text-center">
                      <button type="submit" name='submitupdate' class="btn btn-primary mt-4">Update Employee information</button>
                    </div>
                 
                  </form>

line 31 : for (var i = 0; i < 1; i++) { only runs once, if you wanted to have this add more than one you will need to fix第 31 行: for (var i = 0; i < 1; i++) {只运行一次,如果你想让这个添加多个,你需要修复

also probably the problem you are hung up on line 34 : name="fmlis" later in your code you have name="fmlist'.($qq+1).'可能是你挂了线34问题name="fmlis"在你的代码以后你name="fmlist'.($qq+1).' so, on line 34 you probably want to concat k+1 to the name...因此,在第 34 行,您可能希望将k+1连接到名称...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 动态添加的输入字段已通过验证,无法提交到另一个页面 - Dynamically Added Input fields passed Validation and submit cannot to another page 如何验证动态添加的输入字段 - How to Validate Dynamically Added Input fields 在Laravel 5中验证动态添加的输入字段 - Validating dynamically added input fields in Laravel 5 动态添加的输入字段没有发布? - Dynamically added input fields not getting posted? 动态添加输入字段的PHP表单处理 - PHP form handling for dynamically added input fields 我的联系表格不会验证其输入字段。 我的输入字段为空白时,它将向我发送电子邮件。 有什么建议么? - My contact form will not validate its input fields. It will submit an email to me while my input fields are blank. Any suggestions? 如何将自动完成添加到动态添加的输入字段? 自动完成功能不适用于动态添加的输入字段 - How to add autocomplete to dynamically added input fields? The autocomplete does not work on the dynamically added input fields 通过 jquery 动态添加的输入字段未提交 - Input fields added dynamically through jquery not being submitted 如何在单个数据库列中插入动态添加的输入字段值? - How to insert dynamically added input fields values in single database column? 如何将动态添加的输入字段与父元素/ id相关联? - How to associate dynamically added input fields to parent element/id?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM