0

这是我的 HTML 代码:

<html>
<head>
<title>Login</title>
</head>

<body>


<FORM NAME ="form1" METHOD ="POST" ACTION ="controller.php">

<input type = "text" name = "txtUsername" value = "testuser"><br>
<input type = "text" name = "txtPassword" value = "password"><br>

<Input type = 'Submit' Name ='Login' value="Login">

</FORM>

</body>
</html>

<?PHP

    include_once("controller/Controller.php");  

    function login($username,$password) {
            $controller = new Controller();  
            $controller->invoke("testUsername","testPassword");  
    }

?>

我可以帮忙用两个输入框中的值调用 PHP 登录函数吗?

4

4 回答 4

2

也许

$user = $_POST['txtUsername'];
$pass = $_POST['txtPassword'];

login($user, $pass); 
于 2012-05-17T10:24:09.727 回答
0

可以肯定的是,您可以使用

if (isset($_POST['txtUsername'])&&isset($_POST['txtPassword'])) {
    $username = $_POST['txtUsername'];
    $password = $_POST['txtPassword'];
    login($username, $password);
} else {
    // some logic actions if there no values on txtUsername and txtPassword.
}

另外,我还建议您是否可以使用占位符属性而不是值属性,例如...

<input type="text" name="txtUsername" placeholder="Username"><br>
<input type="password" name="txtPassword"><br>
于 2012-05-17T11:01:07.727 回答
0

我认为您应该执行以下操作:

<?php

if (isset($_POST['Login'])) {
    login($_POST['txtUsername'],$_POST['txtPassword'])
}

当然你需要在里面处理请求controller.php

于 2012-05-17T10:23:16.173 回答
-1
<FORM NAME ="form1" METHOD ="POST" ACTION ="<?php echo $PHP_SELF;?>">

还:

if ( 'POST' == $_SERVER['REQUEST_METHOD'] )
{
  $user = $_POST['txtUsername'];
  $pass = $_POST['txtPassword'];

  login($user, $pass); 
} 
于 2012-05-17T10:27:41.613 回答