好吧,正如标题已经说的那样,我不明白。可能正在做一些非常愚蠢的事情。
这是我正在使用的形式。它不是那么特别。出于测试目的,它现在有一个<button action=submit...>
和一条<input type=submit...>
线。
<div id="cd-login">
<form method="POST" action="index.php" class="cd-form">
<p class="fieldset">
<label class="image-replace cd-email" for="signin-email">E-mail</label>
<input name="login" class="full-width has-padding has-border" type="text" placeholder="Username or E-Mail">
<span class="cd-error-message">Error message here!</span>
</p>
<p class="fieldset">
<label class="image-replace cd-password" for="signin-password">Password</label>
<input name="password" class="full-width has-padding has-border" type="password" placeholder="Password">
<span class="cd-error-message">Error message here!</span>
</p>
<p class="fieldset">
<input type="checkbox" name="remember_me" id="remember-me"/>
<label for="remember_me" onclick="document.getElementById('remember_me').click();">Remember Me</label>
</p>
<p class="fieldset">
<input class="full-width" type="submit" name="submit" value="Login" />
<br />
<button name="submit">Log In</button>
</p>
</form>
然后,它转到 PHP 代码,该代码位于 HTML 代码上方:
<?php
require "config.php";
if(isset($_POST['submit'])){
$identification = $_POST['login'];
$password = $_POST['password'];
if($identification == "" || $password == ""){
$msg = array("Error", "Username / Password Wrong !");
}else{
$login = 'Fr'LS::login($identification, $password, isset($_POST['remember_me']));
if($login === false){
$msg = array("Error", "Username / Password Wrong !");
}else if(is_array($login) && $login['status'] == "blocked"){
$msg = array("Error", "Too many login attempts. You can attempt login after ". $login['minutes'] ." minutes (". $login['seconds'] ." seconds)");
}
}
}
?>
当我用手指敲击按钮时,它可以工作,但我想让它与输入行一起工作。
编辑:不适用于IE,Mozilla或Chrome。<input type=submit ...>
是嗒嗒声。但是砸回车键也不起作用。
替换
<button name="submit">Log In</button>
由:
<input name="submit" type="submit" value="Log In"/>
并消除:)的其他输入
当我给每个按钮/输入一个唯一的名称,然后在索引页面的 POST 中检查该名称.php时,我能够检测到按下了哪个按钮。
原则上,表单上项目的名称帮助我们在 POST 变量中找到它。 在对此类表单进行故障排除时,您始终可以 var 转储 POST 数组,并在处理页面上查看计算机接收的内容。
例如,下面提供了代码的略微修改的副本。 我在以下 html 中运行了您的表单。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div id="cd-login">
<form method="POST" action="index.php" class="cd-form">
<p class="fieldset">
<label class="image-replace cd-email" for="signin-email">E-mail</label>
<input name="login" class="full-width has-padding has-border" type="text" placeholder="Username or E-Mail">
<span class="cd-error-message">Error message here!</span>
</p>
<p class="fieldset">
<label class="image-replace cd-password" for="signin-password">Password</label>
<input name="password" class="full-width has-padding has-border" type="password" placeholder="Password">
<span class="cd-error-message">Error message here!</span>
</p>
<p class="fieldset">
<input type="checkbox" name="remember_me" id="remember-me"/>
<label for="remember_me" onclick="document.getElementById('remember_me').click();">Remember Me</label>
</p>
<p class="fieldset">
<input class="full-width" type="submit" name="submit1" value="Login" />
<br />
<button name="submit2">Log In</button>
</p>
</form>
</body>
</html>
然后,我修改了处理页面,以使用 isset 在 POST 中捕获该名称,并提供一些打印来显示更改正在工作。 我注释掉了该配置.php因为我没有它。
<?php
//require "config.php";
if(isset($_POST['submit1'])){
print ("<p>Hello from Submit1</p>");
var_dump($_POST);
$identification = $_POST['login'];
$password = $_POST['password'];
if($identification == "" || $password == ""){
$msg = array("Error", "Username / Password Wrong !");
}else{
$login = 'Fr'LS::login($identification, $password, isset($_POST['remember_me']));
if($login === false){
$msg = array("Error", "Username / Password Wrong !");
}else if(is_array($login) && $login['status'] == "blocked"){
$msg = array("Error", "Too many login attempts. You can attempt login after ". $login['minutes'] ." minutes (". $login['seconds'] ." seconds)");
}
}
} else {
print ("<p>Submit1 was not recognized.</p>");
var_dump($_POST);
}
?>
当我运行该代码时,我可以显示两个按钮的差异。