【问题标题】:Recover multiple input data恢复多个输入数据
【发布时间】:2017-02-06 19:47:35
【问题描述】:

我有我的 jQuery:

$(document).ready(function() {
    var max_fields      = 10; //maximum input boxes allowed
    var wrapper         = $(".input_fields_wrap");
    var add_button      = $(".add_field_button");

    var x = 1; //initlal text box count
    $(add_button).click(function(e){ //on add input button click
        e.preventDefault();
        if(x < max_fields){ //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><input type="text" name="mytext[]"/><a     href="#" class="remove_field">Remove</a></div>'); //add input box
        }
     });

     $(wrapper).on("click",".remove_field", function(e){ //user click on remove text
         e.preventDefault(); $(this).parent('div').remove(); x--;
     })
});

还有我的 HTML:

<div class="input_fields_wrap">
    <button class="add_field_button">Add More Fields</button>
    <div><input type="text" name="mytext[]"></div>
</div>

发件人:https://www.sanwebe.com/2013/03/addremove-input-fields-dynamically-with-jquery

我想知道,我可以从添加的每个输入中恢复每个数据并保存在我的数据库(MySQL)中吗? 如果可能,我想使用 php,如果没有其他可能,我想使用 jQuery。 非常感谢,

【问题讨论】:

标签: php jquery html mysql input


【解决方案1】:

如果您使用 &lt;form action="processing_page.php" method="POST"&gt;&lt;/form&gt; 包装输入字段

那么当提交表单时,您将能够以这种方式访问​​您的 processing_page.php 中的数据。

$valuesArray = $_POST['mytext'];

您可以在 foreach 语句中使用它来对每个语句执行一些操作(例如在本例中将其打印出来)

foreach($valuesArray as $value) {
    echo "<br>$value";
}

编辑:如果您在实现表单时遇到困难,这里有一个基本的overview/tutorial。请务必查看有关表单本身、操作和方法的部分。

EDIT2:如果您计划将值存储到数据库或在另一个页面上显示,请确保清理所有用户提供的数据。 this thread 中解释了一些好的做法。

【讨论】:

  • 呵呵,我试试这个,谢谢,我会及时通知你的 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-27
  • 1970-01-01
  • 2018-01-01
相关资源
最近更新 更多