【发布时间】:2014-04-16 12:07:46
【问题描述】:
我正在开发基于 Wordpress 构建的项目(由于友好的权限和权限系统,我正在使用 WP),基本上它是由我自己用 PHP 编写的,在我自己的单页上带有一些 javascript 元素。现在我需要你的帮助。我通过我的 PHP 脚本生成了两个表单。每个表单的模板都在 MySQL DB 表中。这是因为对于我的电脑不太熟练的同事,在没有我帮助的情况下需要编辑表格的每个表格中的每个特定行都可以进行友好的编辑和管理。所以我有一些表单管理页面,同事做了一些更改,保存它,脚本将生成编辑后的表单。它完美地工作。脚本生成类似下面的东西(不要看乱七八糟的代码,它只是没有 css 等的测试版)
<form id="f1" method="POST" class="form-product-item" style="display: block;">
<fieldset form="f1" name="f1_f">
<legend> FORM 1 </legend>
<table style="width: 320px; max-width: 320px; float: left; margin: 5px">
<tr class="optional f1r1" name="f1r1_v" style="display: block;" >
<td style="width: 120px; min-width: 120px; max-width: 120px; height: 48px; max-height: 48px;">
<div class="optional f1r1" name="f1r1_v" style="display: block;" class="hidden-txt">Row 1 Form 1: </div>
</td>
<td style="width: 140px; min-width: 140px; max-width: 140px">
<input type="text" class="optional f1r1" name="f1r1_v" style="display: block;" class="hidden-txt" placeholder="Row 1 Form 1" size="15" />
</td>
<td style="width: 60px; max-width: 60px; max-width: 60px">suffix</td>
</tr>
</table>
<div style="clear: both"></div>
</fieldset>
<form id="f2" method="POST" class="form-product-item" style="display: block;">
<fieldset form="f2" name="f2_f">
<legend> FORM 2 </legend>
<table style="width: 320px; max-width: 320px; float: left; margin: 5px">
<tr class="optional f2r1" name="f2r1_v" style="display: block;" >
<td style="width: 120px; min-width: 120px; max-width: 120px; height: 48px; max-height: 48px;">
<div class="optional f2r1" name="f2r1_v" style="display: block;" class="hidden-txt">Row 1 Form 2: </div>
</td>
<td style="width: 140px; min-width: 140px; max-width: 140px">
<select id="f2r1_dm" name="f2r1_v" style="width: 120px">
<option selected>- Choose -</option>
<option>Option 1</option>
<option>Option 2</option>
</select>
</td>
<td style="width: 60px; max-width: 60px; max-width: 60px">suffix</td>
</tr>
<tr class="optional f2r2" name="f2r2_v" style="display: block;" >
<td style="width: 120px; min-width: 120px; max-width: 120px; height: 48px; max-height: 48px;">
<div class="optional f2r2" name="f2r2_v" style="display: block;" class="hidden-txt">Row 2 Form 2: </div>
</td>
<td style="width: 140px; min-width: 140px; max-width: 140px">
<input type="text" class="optional f2r2" name="f2r2_v" style="display: block;" class="hidden-txt" placeholder="Row 2 Form 2" size="15" />
</td>
<td style="width: 60px; max-width: 60px; max-width: 60px">suffix</td>
</tr>
<div style="clear: both"></div>
</table>
</fieldset>
现在我想请教各位朋友,如何在“FORM 2”下方(表单标签之外)制作一个独立的提交按钮,该按钮一次提交来自两个表单的所有字段的值并将其插入数据库。我尝试了一些我在 stackoverflow 上找到的建议,但它们对我不起作用。 我对 PHP 和 Java、AJAX 非常了解,我非常粗略地了解。因此,对于一些建议或分步教程,我将不胜感激。 非常感谢您的帮助;)。
【问题讨论】:
-
抱歉,这里的教程是闻所未闻的,因为它们应该很长。您的两个表单是否都提交到同一个页面?
-
提问时请使用sscce.org原则。
-
@ICanHasCheezburger 感谢您的评论。是的,两个表单都提交到同一个页面
-
@Shalladan 为什么不简单地将所有输入放在一个表单中并一起提交呢?据我所知,即使你的方法(
POST)也是一样的。您是否有理由需要分成两种形式? -
@ICanHasCheezburger 这是因为在数据库表中我有几个模板组用于生成表单。每个模板组(表单)用于不同的产品类型,并在页面顶部有自己的复选框。 javascript 显示或隐藏表单取决于用户在复选框中的选择。之后,用户只填写他需要的表格并只提交他需要的字段。
标签: javascript php jquery mysql forms