将表单提交到php文件中的特定函数
So I have a form in index.php
<? requireonce("action.php"); ?>
<form action="action.php" method="post">
//stuff
</form>
I also have a function to handle that form in action.php
<?
function formHandle(){
//stuff
}
?>
How do I pass the form to formHandle()
entirely within index.php
? I don't want to call formHandle()
in action.php
because it's required in index.php
- and I don't want it to run upon page opening.
所以我在 我还有一个函数来处理 如何将表单传递给 index.php code> p>
中有一个表格
&lt;? requireonce( “action.php的”); ?&gt;
&lt; form action =“action.php”method =“post”&gt;
// stuff
&lt; / form&gt;
code> pre>
action.php code> p>
&lt;?
function formHandle(){
// stuff
}
?&gt;
code> pre>
formHandle() code>完全在
index.php code>中? 我不想在
action.php code>中调用
formHandle() code>,因为它在
index.php code>中是必需的 - 我不想要它 在页面打开时运行。 p>
div>
You can do so in action.php
<?php
if(isset($_POST['myform'])){
formHandle(); // call to a function
}
?>
Change your action to index.php and call formHandle
from within index.php.
<? require_once("action.php"); ?>
<form action="index.php" method="post">
//stuff
</form>
You cannot submit "to a function". Browsers don't care about server-side languages. Browsers communicate via HTTP. HTTP has no concept of "functions" or specific programming languages. You submit something to a URL, and the server handles whatever happens at that URL.