多个提交按钮
我有一个带有两个提交按钮的注册表单。一个提交按钮适用于免费会员帐户,另一个提交按钮适用于高级会员帐户。
我的表单代码是
<form action="post.php" method="post">
<input type="text" name="name" />
<input type="text" name="mail" />
//submit buttons
<input type="submit" value="signup for free member" />
<input type="submit" value="signup for premium member" />
</form>
if($_POST['name'] and $_POST['mail']){
$user_name = $_POST['name'];
$mail = $_POST['mail']
//How i can know he is preimum or free ?
}
现在如何判断用户点击的是免费按钮还是付费按钮?
例子:
if($_POST['free_member']){
$member = 'free';
}else{
$member = 'premium';
}
I have a registration form with two submit buttons. One submit button is for a free member account, and the other is for a premium member account.
My form code is
<form action="post.php" method="post">
<input type="text" name="name" />
<input type="text" name="mail" />
//submit buttons
<input type="submit" value="signup for free member" />
<input type="submit" value="signup for premium member" />
</form>
if($_POST['name'] and $_POST['mail']){
$user_name = $_POST['name'];
$mail = $_POST['mail']
//How i can know he is preimum or free ?
}
Now how can I tell whether the user clicked on the free button or the premium button?
example:
if($_POST['free_member']){
$member = 'free';
}else{
$member = 'premium';
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML
PHP
HTML
PHP
您可以轻松地为提交按钮命名:
然后您的帖子将显示如下:
这不太可扩展。我建议使用 JavaScript 来填充提交时的隐藏字段。示例:
HTML:
JQuery:
PHP:
You could easily give the submit buttons a name:
Then your post will show like this:
This isn't very scalable. I'd recommend using javascript to populate a hidden field on submit. Example:
HTML:
JQuery:
PHP: