我在html中创建了三个表单,第一个是简单表单,另一个是在按钮单击时动态添加表行但是我想在按下第一个表单上的保存按钮时保存表单。是否可以使用PHP来做到这一点?我搜索谷歌并找到类似jQuery的东西,但即使这似乎没有用,任何人都可以帮忙吗? 这是我的剧本:
<script>
$(document).ready(function() {
$("#submit").click(function() {
$.post($("#form1").attr("action"), $("#form1").serialize(),
function() {
$.post($("#form2").attr("action"), $("#form1").serialize(),
function() {
$.post($("#form3").attr("action"), $("#form2").serialize(),
function() {
alert('Both forms submitted');
});
});
});
});
});
</script>
<table border="1" align="right">
<tr>
<td>
<input class="cmdsave" type="submit" id="submit" name="save" value="Save" />
</td>
<td>
</td>
<td>
<input class="cmdexit" type="button" onClick="window.history.back()" value="Exit" />
</td>
</tr>
</table>
</nav>
<body onLoad="document.machine.code.focus()">
<div id="content">
<section class="tab" id="home">
<!--<center><font size="5px" color="#6B6A68"><strong>Customer - Add</strong></font></center> -->
<form action="quotation.php" class="general2" align="left" name="quot" id="form1" method="POST">
<input type="hidden" name="vouchno" value="<?php echo ($addflag == 0) ? $get['vouchno'] : ""; ?>">
<table border="0px" width="100%">
<tr>
<td><br/></td>
</tr>
<tr>
<td width="200px" align="right"><label for=""><font color="0099FF" size="3px">Quotation No.</font><span></span></label></td>
<td align="left"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="code" value="<?php echo ($addflag == 0) ? $get['code'] : ""; ?>" class="form-input-code" />
<label for=""><font color="0099FF" size="3px"> Date </font><span></span></label><input type="date" size="80" name="oildate" value="<?php echo ($addflag == 0) ? $get['vouchdt'] : $today; ?>"/>
</td>
</tr>
<tr>
<td width="200px" align="right"><label for=""><font color="0099FF" size="3px">Party Name </font><span></span></label></td>
<td align="left"><select data-placeholder="Party" style="width:332px;" name="cmbparty" class="chzn-select-deselect" onChange="showyear('party.php?code='+this.value);">
<option value="<?php echo ($addflag == 0) ? $get['party'] : ""; ?>"><?php echo ($addflag == 0) ? $get['party'] : ""; ?></option>
<?php
$mown = mysql_query("SELECT accode, `name` FROM accmast WHERE grpcode='010'") or die(mysql_error());
while($trow = mysql_fetch_array($mown)){
echo "<option value=$trow[accode]>$trow[name]</option>";
}
?>
</select></td>
</tr>
<tr>
<td colspan="9">
<div id="parthint" style=""></div>
</td>
</tr>
<tr>
<td width="200px" align="right"><label for=""><font color="" size="3px">Ref. No. </font><span></span></label></td>
<td align="left"><input type="text" id="refno" size="20" maxlength="20" name="refno" value="<?php echo ($addflag == 0) ? $get['refno'] : ""; ?>" class="form-input-c20"/></td>
</tr>
<tr>
<td width="200px" align="right"><label for=""><font color="" size="3px">Kindly Attn. </font><span></span></label></td>
<td align="left"><input type="text" id="refno" size="20" maxlength="80" name="attn" value="<?php echo ($addflag == 0) ? $get['attn'] : ""; ?>" class="form-input-add"/></td>
</tr>
<tr>
<td width="200px" align="right"><label for=""><font color="" size="3px">Subject. </font><span></span></label></td>
<td align="left"><textarea name="subject" rows="3" cols="70" class="form-input-textarea"><?php echo ($addflag == 0) ? $get['subject'] : ""; ?></textarea></td>
</tr>
<tr>
<td colspan="9">
<hr />
</td>
</tr>
<tr>
<td width="200px" align="right"><label for=""><font color="0099FF" size="3px">Dear Sir / Madam, </font><span></span></label></td>
<td></td>
</tr>
<tr>
<td></td>
<td align="left"><textarea name="msg" cols="70" class="form-input-textareaxl"><?php echo ($addflag == 0) ? $get['message'] : ""; ?></textarea></td>
</tr>
<tr>
<td width="200px" align="right"><label for=""><font color="0099FF" size="3px">Status</font><span></span></label></td>
<td align="left"><select data-placeholder="Status" style="width:332px;" name="cmbstatus" class="chzn-select-deselect">
<option value="<?php echo ($addflag == 0) ? $get['status'] : ""; ?>"><?php echo ($addflag == 0) ? $get['status'] : ""; ?></option>
<option value="<?php echo ($addflag == 0) ? $get['status'] : "Pending"; ?>"><?php echo ($addflag == 0) ? $get['status'] : "Pending"; ?></option>
<option value="<?php echo ($addflag == 0) ? $get['status'] : "Approved"; ?>"><?php echo ($addflag == 0) ? $get['status'] : "Approved"; ?></option>
<option value="<?php echo ($addflag == 0) ? $get['status'] : "Rejected"; ?>"><?php echo ($addflag == 0) ? $get['status'] : "Rejected"; ?></option>
</select></td>
</tr>
<tr>
<td width="200px" align="right"><label for=""><font color="" size="3px">Remarks. </font><span></span></label></td>
<td align="left"><textarea name="rem" rows="3" cols="70" class="form-input-textarea"><?php echo ($addflag == 0) ? $get['subject'] : ""; ?></textarea></td>
</tr>
<tr>
<td><br/></td>
</tr>
<tr>
<td></td><td>
</td>
<td>
</tr>
</table>
</form>
</section>
<section class="tab" id="company"></section>
<section class="tab" id="portfolio">
<form action="quotation.php" class="general2" align="left" name="quot2" id="form2" method="POST">
<table border="1px" width="90%" id="data">
<tr>
<td><br /></td>
</tr>
<tr>
<td><br /></td>
</tr>
<tr>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Order</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Sr No.</font><span></span></label></td>
<td width="580px" align="center"><label for=""><font color="#0099FF" size="3px">Description</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Unit</font><span></span></label></td>
<td width="130px" align="center"><label for=""><font color="#0099FF" size="3px">Rate</font><span></span></label></td>
</tr>
<?php if($addflag==0){
$qry = mysql_query("SELECT * FROM `quotdtl` WHERE vouchno='$getvouch'") or die(mysql_error());
$ctr = 0;
while ($row = mysql_fetch_array($qry)) {
echo "<td align=\"center\"><input type=\"text\" size=\"6\" maxlength=\"6\" id=\"code\" maxlength=\"6\" name=\"ord_$ctr\" value=\"$row[orderby]\" class=\"form-input-oth\" /></td>";
echo "<td align=\"center\"><input type=\"text\" size=\"6\" maxlength=\"6\" id=\"code\" maxlength=\"6\" name=\"srno_$ctr\" value=\"$row[srno]\" class=\"form-input-oth\" /></td>";
echo "<td align=\"center\"><textarea name=\"descrip_1\" cols=\"70\" class=\"form-input-textarea\">$row[descrip]</textarea></td>";
echo "<td align=\"center\"><input type=\"text\" size=\"6\" maxlength=\"9\" id=\"code\" maxlength=\"6\" name=\"unit_$ctr\" value=\"$row[unit]\" class=\"form-input-rate\"/></td> ";
echo "<td align=\"center\"><input type=\"text\" size=\"6\" maxlength=\"9\" id=\"code\" maxlength=\"6\" name=\"rate_$ctr\" value=\"$row[rate]\" class=\"form-input-rate\" /></td>";
$ctr++;
}
}else{
?>
<tr>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_1" value="" class="form-input-oth" /></td>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_1" value="" class="form-input-oth" /></td>
<td align="center"><textarea name="descrip_1" cols="20" class="form-input-textarea"></textarea></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_1" value="" class="form-input-rate" /></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_1" value="" class="form-input-rate" /></td>
</tr>
<tr>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_2" value="" class="form-input-oth" /></td>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_2" value="" class="form-input-oth" /></td>
<td align="center"><textarea name="descrip_2" cols="20" class="form-input-textarea"></textarea></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_2" value="" class="form-input-rate" /></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_2" value="" class="form-input-rate" /></td>
</tr>
<tr>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_3" value="" class="form-input-oth" /></td>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_3" value="" class="form-input-oth" /></td>
<td align="center"><textarea name="descrip_3" cols="20" class="form-input-textarea"></textarea></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_3" value="" class="form-input-rate" /></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_3" value="" class="form-input-rate" /></td>
</tr>
<tr>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_4" value="" class="form-input-oth" /></td>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_4" value="" class="form-input-oth" /></td>
<td align="center"><textarea name="descrip_4" cols="20" class="form-input-textarea"></textarea></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_4" value="" class="form-input-rate" /></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_4" value="" class="form-input-rate" /></td>
</tr>
<tr>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_5" value="" class="form-input-oth" /></td>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_5" value="" class="form-input-oth" /></td>
<td align="center"><textarea name="descrip_5" cols="20" class="form-input-textarea"></textarea></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_5" value="" class="form-input-rate" /></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_5" value="" class="form-input-rate" /></td>
</tr>
<tr>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_6" value="" class="form-input-oth" /></td>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_6" value="" class="form-input-oth" /></td>
<td align="center"><textarea name="descrip_6" cols="20" class="form-input-textarea"></textarea></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_6" value="" class="form-input-rate" /></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_6" value="" class="form-input-rate" /></td>
</tr>
<tr>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="ord_7" value="" class="form-input-oth" /></td>
<td align="center"><input type="text" size="6" maxlength="6" id="code" maxlength="6" name="srno_7" value="" class="form-input-oth" /></td>
<td align="center"><textarea name="descrip_7" cols="20" class="form-input-textarea"></textarea></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="unit_7" value="" class="form-input-rate" /></td>
<td align="center"><input type="text" size="6" maxlength="9" id="code" maxlength="6" name="rate_7" value="" class="form-input-rate" /></td>
</tr>
<?php }?>
</table>
<input type="button" id="addnew" class="classname" name="addnew" value="+" />
<input type="hidden" id="items" name="items" value="<?php echo ($addflag == 0) ? $ctr : 7; ?>" />
</form>
</section>
<section class="tab" id="contact">
<form action="quotation.php" class="general2" align="left" name="quot2" id="form3" method="POST">
<table border="1px" width="90%" id="data2">
<tr>
<td><br /></td>
</tr>
<tr>
<td width="" align="left"><label for=""><font color="#0099FF" size="3px">Notes,</font><span></span></label></td>
<td></td><td></td>
</tr>
<?php if($addflag==0){
$qry = mysql_query("SELECT * FROM `quotnotes` WHERE vouchno='$getvouch'") or die(mysql_error());
$mctr = 0;
while ($rownote = mysql_fetch_array($qry)) {
echo "<td align=\"left\"><textarea name=\"note_1\" cols=\"80\" class=\"form-input-textareaxxl\">$rownote[notes]</textarea></td>";
$mctr++;
}
}else{
?>
<tr></tr>
<tr>
<td align="left"><textarea name="note_1" cols="80" class="form-input-textareaxxl"></textarea></td>
</tr>
<tr>
<td align="left"><textarea name="note_2" cols="80" class="form-input-textareaxxl"></textarea></td>
</tr>
<tr>
<td align="left"><textarea name="note_3" cols="80" class="form-input-textareaxxl"></textarea></td>
</tr>
<tr>
<td align="left"><textarea name="note_4" cols="80" class="form-input-textareaxxl"></textarea></td>
</tr>
<tr>
<td align="left"><textarea name="note_5" cols="80" class="form-input-textareaxxl"></textarea></td>
</tr>
<?php }?>
</table>
<input type="button" id="addnew2" class="classname" name="addnew" value="+" />
<input type="hidden" id="h" name="h" value="<?php echo ($addflag == 0) ? $mctr : 5; ?>" />
</form>
答案 0 :(得分:0)
如果我理解了你想要的内容,那么第二次调用后就会出现错误: form1 应该是 form2 ,在第三个 form2 中应该是 form3 尝试在每个帖子之前发出警报以更有效地进行调试。这将按顺序1-2-3发送每个表格。
<script>
$(document).ready(function() {
$("#submit").click(function(event) {
alert('send 1st form');
$.post($("#form1").attr("action"), $("#form1").serialize(),
function() {
alert('send 2nd form');
$.post($("#form2").attr("action"), $("#form2").serialize(),
function() {
alert('send 3th form');
$.post($("#form3").attr("action"), $("#form3").serialize(),
function() {
alert('Both forms submitted');
});
});
});
event.preventDefault();
});
});
</script>
编辑:添加了event.preventDefault(感谢Akam)