PHP - HTML形式有两种可能的行为? [英] PHP - HTML form two possible actions?
问题描述
我正在创建一个注册页面,我想让用户有机会查看他们的信息并返回并编辑它,然后再点击一个确认按钮将其插入数据库。
I'm creating a registration page and I would like to give the user the opportunity to review their information and go back and edit it before clicking a confirm button which inserts it into the database.
是否有一种方法可以包含两个指向不同脚本的提交按钮,或者我必须复制整个表单,但使用隐藏字段?
Is there a way to include two submit buttons which point to different scripts or would I have to duplicate the entire form but use hidden fields instead?
任何建议赞赏。
谢谢。
推荐答案
两个提交按钮的名称不同:
You can use two submit buttons with different names:
<input type="submit" name="next" value="Next Step">
<input type="submit" name="prev" value="Previous Step">
然后检查提交按钮是否已被激活:
And then check what submit button has been activated:
if (isset($_POST['next'])) {
// next step
} else if (isset($_POST['prev'])) {
// previous step
}
只有激活的提交按钮成功 :
$ b
This works because only the activated submit button is successful:
- 如果一个表单包含多个提交按钮,只有激活的提交按钮
这篇关于PHP - HTML形式有两种可能的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!