Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何使用jquery添加行和提交表单_Php_Jquery_Html_Twitter Bootstrap - Fatal编程技术网

Php 如何使用jquery添加行和提交表单

Php 如何使用jquery添加行和提交表单,php,jquery,html,twitter-bootstrap,Php,Jquery,Html,Twitter Bootstrap,我有以下代码 <h3>Guests</h3> <form class="form-inline"> <fieldset> <label class="control-label" for="input01">First Name:</label> <input type="text" class="inp

我有以下代码

<h3>Guests</h3>
<form class="form-inline">
    <fieldset>                                  
        <label class="control-label" for="input01">First Name:</label>
            <input type="text" class="input-small" id="input01">                            
        <label class="control-label" for="input01">&nbsp;&nbsp;Middle Name:</label>
            <input type="text" class="input-small" id="input01">
        <label class="control-label" for="input01">&nbsp;&nbsp;Last Name:</label>
            <input type="text" class="input-small" id="input01">
        <label class="control-label" for="input01">&nbsp;&nbsp;Birthday:</label>
            <input type="text" class="input-small" id="input01">>                   
    </fieldset>
</form>
客人
名字:
中名:
姓氏:
生日:
>                   
我希望能够添加一个按钮,上面写着“添加更多”,并让它添加一行新的元素,最终将表单保存到数据库中。如果我添加一个添加行的按钮(这需要向数据库中添加一条记录。对于已更改的记录,我希望更新数据库中的记录)

因此,多方面的问题是:

  • 当他们点击“添加更多”按钮时,我认为这是最好的 将记录添加到数据库的时间。然后当我保存 表单中,我循环并更新表单中的所有记录。或者是 还有其他想法吗
  • 要点:是否有一个例子,某人可以建议如何循环并执行更新

  • 我建议点击“添加更多”按钮 不是将记录添加到数据库的最佳时间。想象一下,有人点击按钮,却没有实际填写该行。 很酷,你想得到所有的花式与你的形式和提供 更具交互性的用户体验,但不要减损“表单” 101”:有一个“提交/保存”按钮。在保存到数据库之前进行验证 数据库逻辑非常简单:您需要行的ID 隐藏在某个地方(可能是隐藏的文本字段)。逻辑是这样的 比如,“我收到了一封$u的邮件。我已经检查过 所需数据存在且正常。我是否有ID?是:更新。否:
    插入。“

    我建议点击“添加更多”按钮 不是将记录添加到数据库的最佳时间。想象一下,有人点击按钮,却没有实际填写该行。 很酷,你想得到所有的花式与你的形式和提供 更具交互性的用户体验,但不要减损“表单” 101”:有一个“提交/保存”按钮。在保存到数据库之前进行验证 数据库逻辑非常简单:您需要行的ID 隐藏在某个地方(可能是隐藏的文本字段)。逻辑是这样的 比如,“我收到了一封$u的邮件。我已经检查过 所需数据存在且正常。我是否有ID?是:更新。否:
    插入。“

    我同意同时将值保存到数据库不是一个好主意,请再次思考您在这里尝试的是什么。当有人单击“添加更多””时,您将有新行,然后您将这些行的值添加到数据库中,但是初始行的值呢

    这可能会有所帮助

        <label class="control-label" for="input01">First Name:</label>
            <input type="text" class="input-small" id="input01" name="firstname[]">                            
        <label class="control-label" for="input01">&nbsp;&nbsp;Middle Name:</label>
            <input type="text" class="input-small" id="input01" name="middlename[]">
        <label class="control-label" for="input01">&nbsp;&nbsp;Last Name:</label>
            <input type="text" class="input-small" id="input01" name="lastname[]">
        <label class="control-label" for="input01">&nbsp;&nbsp;Birthday:</label>
            <input type="text" class="input-small" id="input01" name=birthday[]>                   
    
    名字:
    中名:
    姓氏:
    生日:
    
    现在保存在js变量中单击按钮时要显示的字段

    var extras=$('fieldset').clone()

    然后

    $(“.yourAddButton”)。单击(函数(){ $(“表格”)。附加(额外); });


    最后,别忘了使用submit按钮来提交表单。

    我同意同时将值保存到数据库不是一个好主意,请再次思考您在这里尝试的是什么。当有人单击“添加更多””时,您将有新行,然后您将这些行的值添加到数据库中,但是初始行的值呢

    这可能会有所帮助

        <label class="control-label" for="input01">First Name:</label>
            <input type="text" class="input-small" id="input01" name="firstname[]">                            
        <label class="control-label" for="input01">&nbsp;&nbsp;Middle Name:</label>
            <input type="text" class="input-small" id="input01" name="middlename[]">
        <label class="control-label" for="input01">&nbsp;&nbsp;Last Name:</label>
            <input type="text" class="input-small" id="input01" name="lastname[]">
        <label class="control-label" for="input01">&nbsp;&nbsp;Birthday:</label>
            <input type="text" class="input-small" id="input01" name=birthday[]>                   
    
    名字:
    中名:
    姓氏:
    生日:
    
    现在保存在js变量中单击按钮时要显示的字段

    var extras=$('fieldset').clone()

    然后

    $(“.yourAddButton”)。单击(函数(){ $(“表格”)。附加(额外); });

    最后,别忘了使用提交按钮来提交表单