我有一个文件index.php,其中包含一个登录表单,包括电子邮件地址字段,密码字段,要检查的框和两个提交按钮:
我正在尝试使用javascript提交表单,并跟踪已提交的按钮以执行正确的操作。请参阅下面的代码。
<form id="form" name="form" method="post" action="index.php">
<input type="text" name="email" id="email" placeholder="Email address" />
<input type="password" name="password" id="password" placeholder="Password" />
<input type="radio" id="box" name="box"><label for="box">Please check this box if you want to log in.</label>
<input type="button" id="log_in" name="log_in" value="Log in" onclick="return check_box();"/>
<input type="button" id="change_password" name="change_password" value="Password forgotten?" onclick="return confirmation();"/>
</form>
function confirmation(){
if (!confirm("A new password will be generated and sent to your email address. Please make sure that your email address is written correctly, and click on Confirm to proceed.")) {
return FALSE;
}
else{
var form = document.getElementById('form');
form.submit();
}
}
function check_box(){
var success = document.querySelector("input[name=box]:checked");
if(!success){
alert("Please check the box.");
}
else{
var form = document.getElementById('form');
form.submit();
}
}
我的问题是在提交表单时检索按钮的值。我试过了
if(isset($_POST['log_in']))
检测用户是否一直在尝试登录,
if(isset($_POST['change_password']))
检测用户是否想要更改密码。但是这些测试总是返回FALSE。错误在哪里?
提前谢谢。