2 回答
TA贡献1906条经验 获得超3个赞
由于您似乎向两个不同的处理程序发送了完全相同的数据,因此您可以抛硬币——假设您只提交一个表单,然后在filecreate.php.
当您发送表单时,您不能在同一个 HTTP 请求中发送两个单独的表单 - 因此您可以通过异步方法同时执行它们,或者在提交一个表单后在后端处理它们。
由于您尚未展示任何 PHP 代码,因此我正在做一些假设并编写一些伪代码,但这应该足以让您入门。
所以首先,为你的表单设置一个静态的动作属性。
<form id="add" action="filecreate.php">
<input type="text" name="test">
<input type="submit">
</form>
如果您通过 POST 发送它,那么您还需要指定方法,
<form id="add" action="filecreate.php" method="POST">
然后,在 PHP 中,如果将它包含在另一个文件中,则可以同时执行这两个文件。意思是,在您的 中filecreate.php,您包括filecreate.fr.php. 一旦你这样做了,那个文件的内容也将被执行。
<?php
// Once you require the file, it will be executed in place
require "filecreate.fr.php";
// .. handle the rest of your normal execution here.
也就是说,如果你多次做非常相似的事情,只是使用不同的数据,你可能想要为它创建函数 - 遵循 DRY 原则(“不要重复你自己”),你可能可以创建一个函数处理结构和处理,然后通过该函数单独发送数据。
TA贡献1804条经验 获得超3个赞
尝试这个 :
<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 关注
- 146 浏览
添加回答
举报