问题描述
请帮我解决一个问题。
我的主页上有两种表单,我希望用户在不同的时间填写和提交。我的问题是,我只想为他们两个只有一个处理页面。通常我可以在单独的页面上做到这一点。但我想知道是否可以在同一页面上完成。
please i need your help with an issue.I have two forms on my homepage that i'll like users to fill and submit at different times. My problem is that i'll like to have only one processing page for both of them. Normally i can do this in seperate pages. But i'll like to know if doing it on the same page is possible.
好的..如果我在表单A中提交,在操作页面上,不会有未定义索引表格B的变量,尚未提交,并且当然使用GET并不提供建议。
Okay.. If i submit form A, on the action page, wont there be Undefined Index for variable of form B, that has not being submitted, and ofcourse using a GET is not adviced.
感谢您的时间和耐心。
推荐答案
这样做并不是完全没有听过。通常,在表单元素的action属性中传递一个不同的参数,如 /submit.php?action=register
或 /submit.php?action=激活
。
It's not completely unheard of to do this. Quite often, a different parameter is passed in the form element's action attribute like /submit.php?action=register
or /submit.php?action=activate
.
所以,你有这样的代码:
So, you have code like this:
if ($_GET['action'] == 'register') {
// Register user
} else if($_GET['action'] == 'activate' {
// Activate user
}
但是,您也可以更改提交按钮的值,并且对于两种表单都具有相同的action属性:
However, you could also just change the value of the submit button and have the action attribute the same for both forms:
if (isset($_POST['submit'])) {
if ($_POST['submit'] == 'register') {
// Register user
} else if($_POST['submit'] == 'activate') {
// Activate user
}
}
这篇关于多个表单和一个处理页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!