2 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊
由于您似乎向兩個(gè)不同的處理程序發(fā)送了完全相同的數(shù)據(jù),因此您可以拋硬幣——假設(shè)您只提交一個(gè)表單,然后在filecreate.php.
當(dāng)您發(fā)送表單時(shí),您不能在同一個(gè) HTTP 請(qǐng)求中發(fā)送兩個(gè)單獨(dú)的表單 - 因此您可以通過異步方法同時(shí)執(zhí)行它們,或者在提交一個(gè)表單后在后端處理它們。
由于您尚未展示任何 PHP 代碼,因此我正在做一些假設(shè)并編寫一些偽代碼,但這應(yīng)該足以讓您入門。
所以首先,為你的表單設(shè)置一個(gè)靜態(tài)的動(dòng)作屬性。
<form id="add" action="filecreate.php">
<input type="text" name="test">
<input type="submit">
</form>
如果您通過 POST 發(fā)送它,那么您還需要指定方法,
<form id="add" action="filecreate.php" method="POST">
然后,在 PHP 中,如果將它包含在另一個(gè)文件中,則可以同時(shí)執(zhí)行這兩個(gè)文件。意思是,在您的 中filecreate.php,您包括filecreate.fr.php. 一旦你這樣做了,那個(gè)文件的內(nèi)容也將被執(zhí)行。
<?php
// Once you require the file, it will be executed in place
require "filecreate.fr.php";
// .. handle the rest of your normal execution here.
也就是說,如果你多次做非常相似的事情,只是使用不同的數(shù)據(jù),你可能想要為它創(chuàng)建函數(shù) - 遵循 DRY 原則(“不要重復(fù)你自己”),你可能可以創(chuàng)建一個(gè)函數(shù)處理結(jié)構(gòu)和處理,然后通過該函數(shù)單獨(dú)發(fā)送數(shù)據(jù)。

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊
嘗試這個(gè) :
<form id="add">
<input type="text" name="test">
<input type="button" onclick="return SubmitForm();">
</form>
function SubmitForm()
{
if(document.forms['add'].onsubmit())
{
document.forms['add'].action='filecreate.php';
document.forms['add'].submit();
document.forms['add'].action='filecreate.fr.php';
document.forms['add'].submit();
}
return true;
}
- 2 回答
- 0 關(guān)注
- 164 瀏覽
添加回答
舉報(bào)