PHP 提交表单后包含
当谈到 PHP 和表单时,我有点菜鸟,但我会尽力解释。
我想做的是创建一系列包含在内容容器中的表单。用户填写表单#1,单击“提交”,然后继续填写表单#2,依此类推。每个表单中的数据都会发送到下一个表单并存储在隐藏字段中,一旦表单#3 完成,数据就会全部插入到 MYSQL 数据库中。
到目前为止,所有这些都运行良好。我遇到的问题是我似乎无法让提交按钮按预期工作。我的设想是,用户将导航到“blah.com/recruit.php?p=form1”并填写表单#1,然后提交按钮会将他们带到“blah.com/recruit.php?p=” form2' 等等。
<form id="form" action="recruit.php?p=form2" method="post">
这不起作用,但我不明白为什么。我浏览了互联网,发现了一些讨论类似问题的论坛主题,但没有一个主题真正详细介绍了解决方案或为什么这种方法行不通。
谁能向我解释一下我做错了什么?我有一种感觉,这是愚蠢的明显,但我无法指出它。
非常感谢,
斯普拉戈尔
I'm a bit of a noob when it comes to PHP and forms but I will do my best to explain.
What I am trying to do is create a series of forms that are included in a content container. The user fills out form#1, clicks 'submit' and moves on to fill in form#2 and so on. The data from each form is sent to the next form and is stored in hidden fields and once form#3 is completed the data is all inserted into a MYSQL database.
All of this works fine so far. The problem I am having is that I can't seem to get the submit buttons to work as intended. What I had envisioned is that the user would navigate to 'blah.com/recruit.php?p=form1' and fill out form#1 and then the submit button would take them to 'blah.com/recruit.php?p=form2' and so forth.
<form id="form" action="recruit.php?p=form2" method="post">
This does not work but I don't understand why. I've looked around the internet and I've found a few forum topics that discuss similar issues but none of them actually go into much detail about the solution or why this approach won't work.
Can anyone explain to me what it is I am doing wrong please? I have a feeling it is stupidly obvious but I can't put my finger on it.
Many thanks,
Splatgore
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一些工作示例代码可以完成我认为您想要实现的目标:
Some working sample code to do what I think you're trying to achieve:
看起来你有嵌套的表单。
这在 HTML 中是不可能的。
如果您采用自己的方法,只需始终使用相同的提交按钮即可生成相同的 php 脚本。
在 php 脚本中检查已设置哪些隐藏字段以查看进程进行到什么程度。
在我看来,更好的方法很难将数据存储在会话变量中,并且总是导致另一个表单页面。
It looks somehow you have nested forms.
This is not possible in HTML.
If you are going with your approach, just use always the same submit button which leads to the same php script.
In the php script check which hidden fields are already set to see how far the process is.
A better approach IMO would be tough to store the data in a session var and always lead to another form page.