简体   繁体   English

if(isset($ _ POST ['submit']))函数响应按钮,但不响应type = submit

[英]if(isset($_POST['submit'])) function responds to button but not to input type=submit

Well, as the title already says, I'm not getting it. 好吧,正如标题已经说的那样,我不明白。 Probebly doing something very stupid. 认真地做一些非常愚蠢的事情。

This is the form that I'm using. 这是我正在使用的表格。 Its not that special. 它不是那么特别。 For testing purpose it now has a <button action=submit...> and a <input type=submit...> line. 为了进行测试,它现在具有<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>

It then goes to the PHP code which is alligned above the HTML code: 然后转到位于HTML代码上方的PHP代码:

<?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)");
        }
    }
}
?>

When I smack my finger on the button it works, but I want to get it to work with an input line. 当我在按钮上敲击手指时,它可以工作,但是我想使其与输入线一起工作。

EDIT: Doesn't work in IE, Mozilla or Chrome. 编辑:在IE,Mozilla或Chrome中不起作用。 The <input type=submit ...> is clickeble. <input type=submit ...>是clickeble。 But smashing the enter-key doesn't work either. 但是粉碎回车键也不起作用。

replace 更换

 <button name="submit">Log In</button> 

by : 创建人:

 <input name="submit" type="submit" value="Log In"/> 
and eliminate the other input over :) 并消除其他输入:)

When I gave each button/input a unique name, and then checked for that name in POST in your index.php page, I was able to detect which button was pressed. 当我给每个按钮/输入一个唯一的名称,然后在index.php页面的POST中检查该名称时,我能够检测到按下了哪个按钮。

In principle, it's the name of the item on the form that helps us find it in the POST variables. 原则上,正是表单上项目的名称帮助我们在POST变量中找到它。 When troubleshooting forms like this, you can always var dump the POST array and see what the computer is receiving on the processing page. 对此类表单进行故障排除时,您始终可以var dump POST数组,并在处理页面上查看计算机收到的内容。

As an example, a slightly modified copy of your code is presented below. 例如,下面显示了您的代码的略微修改的副本。 I ran your form in the following html. 我在以下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>

Then, I modified the processing page to catch that name in POST with the isset and provide some printing that will show the change is working. 然后,我修改了处理页面,以便在具有isset的POST中捕获该名称,并提供一些打印来显示所做的更改正在起作用。 I commented out that config.php because I did not have it. 我注释掉了config.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);
}
?>

When I ran that code, I could show the difference in the two buttons. 当我运行该代码时,我可以在两个按钮上显示差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM