获取HTML输入框的字段值,这些字段值为;呼应;PHP内部
我正在尝试创建一个登录/激活页面(作为任务要求的一部分),如果激活成功,用户将看到登录页面。我在PHP块中有登录页面的HTML代码(因为我不知道隐藏表单的最安全和最安全的方法),我想知道如何获取用户在用户名、密码字段中输入的信息 这是我的密码:获取HTML输入框的字段值,这些字段值为;呼应;PHP内部,php,html,Php,Html,我正在尝试创建一个登录/激活页面(作为任务要求的一部分),如果激活成功,用户将看到登录页面。我在PHP块中有登录页面的HTML代码(因为我不知道隐藏表单的最安全和最安全的方法),我想知道如何获取用户在用户名、密码字段中输入的信息 这是我的密码: <?php /* Project information: * Author: Michael Warren * FileName: login.php * Creation Date: 9/12/2014 */ // create var
<?php
/* Project information:
* Author: Michael Warren
* FileName: login.php
* Creation Date: 9/12/2014
*/
// create variables for userName (or email address), password, needsActivation, activationCode
$userName = "";
$password = "";
$needsActivation = ((isset($_POST["activate"])) ? (bool)($_POST["activate"]) : false);
$activationCode = "";
// variable to check if the current user of this page has been activated
$userActivated = !($needsActivation);
// JavaScript messages that tell the user the status of their activation
$activationSuccess = '<script>alert("Activation successful! Bringing up the log in page.");</script>';
$activationFailed = '<script>alert("Activation failed. You have been sent another activation e-mail.");</script>';
// JavaScript messages that tell the user about the login
$missingUserName = '<script>alert("Username required.");</script>';
$missingPassword = '<script>alert("Password required");</script>';
$invalidUserName = '<script>alert("Invalid username entered.");</script>';
$invalidPassword = '<script>alert("Invalid password entered.");</script>';
$successfulLogin = '<script>alert("You have successfully logged in!");</script>';
if ($needsActivation)
{
// get the information from the query string (or the POSTed data)
$userName = $_POST["name"];
$password = $_POST["password"];
$activationCode = $_POST["activationCode"];
// check the activationCode
// if the activationCode checks out (in this project, that just means that the length of the activation code is 50 characters)
if (strlen($activationCode) == 50)
{
// user has been activated
$userActivated = true;
// send email and/or JavaScript message telling them that
echo $activationSuccess;
mail($userName,
"Activation Successful",
<<<HERE
Your activation was a success. You can now use this site. Your login credentials are as follows:
UserName: $userName
Password: $password
HERE
);
}
// otherwise
else
{
// deny access to login page
// send email to the user to try again, and inform them that it has been done
echo $activationFailed;
}
}
if ($userActivated)
{
// show the login page
echo <<<HERE
<div id="contents">
<div id="clearfix">
<div id="main">
<h1>Login</h1>
<p>Log in to the site using your e-mail as your password.</p>
<form class="message">
<label>
<p class="descriptor">User name: </p><input type="text" name="userNameField" value=""></input>
</label>
<br>
<label>
<p class="descriptor">Password: </p><input type="password" name="passwordField" value=""></input>
</label>
<br>
<input type="submit" name="LogInButton" value="Log in"></input>
</form>
</div>
</div>
</div>
HERE;
}
function checkLogin()
{
}
?>
<body>
</html>
如果您计划将表单发回PHP,请在表单上设置一个action属性,并通过submit按钮进行发布,在服务器端,您可以从$\u post数组访问这些值
如果您想在客户端捕获这些值,请使用jQuery或纯JavaScript,可能会为输入分配一些ID,以便您可以轻松地将它们作为目标。我的另一个想法是我以前使用的:将按钮发布数据到页面,然后检查它IF(isset($\u POST['LogInButton'))
,但我担心的是萨米很难理解你的问题。如果用户尚未登录,则您没有用户名和密码,那么如何自动填写字段?只有在用户提交登录表单后才会发送,而不是在表单显示时。当用户点击该按钮时,我想您可以按名称获取字段。这就是我要问的。点击什么按钮,提交按钮?这将发送表单,然后脚本将再次运行。这次,$\u POST['username']
和$\u POST['password']
将包含用户在字段中输入的内容。这就是我所想的。$\u POST数组是否会包含来自输入字段的值,就好像HTML是在PHP块之外声明的一样?也就是说,我可以像往常一样使用我的一个想法并按名称从字段中捕获输入吗?浏览器永远不会知道它们被声明在哪里,所以它们的行为通常会像普通表单一样。这是因为,对于PHP代码来说,所有HTML/CSS/JavaScript都只是字符串吗?@MikeWarren这是正确的。它们只是线。客户端处理的这些字符串的解释由浏览器负责。在呈现页面后,只需查看源代码,您将看到纯html/css/js