我有以下代碼,用於檢查密碼是否足夠強大並匹配並返回布爾值。有沒有辦法使用這個值來取消默認爲灰色的按鈕,如果返回的值是真的?我假設你會這樣做在JavaScript中,但我不知道。使用布爾值來解鎖按鈕
<?php
include("RegisterCheck.php");
?>
<form action="" method="post" style="text-align:center">
<input type="text" placeholder="Username" id="user" name="user"><br/><br/>
<input type="password" placeholder="Password" id="pass" name="pass"><br/><br/>
<input type="password" placeholder="Re-Password" id="CheckPass" name="CheckPass"><br/><br/>
<input type="submit" value="Check availibility" name="Check Account">
</form>
<form action="CreateAccount.php" method="post" style="text-align:center">
<input type="button" id="Create" name="Create" value="Create Account" onclick="greybutton(CreateButton)" />
</form>
。
<?php
$pass = $_POST['pass'];
$CheckPass = $_POST['CheckPass'];
function CheckSame($pass, $CheckPass){
return $pass == $CheckPass;
}
function CheckStrength($pass)
{
$errors = [];
if (strlen($pass) < 8) {
$errors[] = "Password too short!";
}
if (!preg_match("#[0-9]+#", $pass)) {
$errors[] = "Password must include at least one number!";
}
if (!preg_match("#[a-zA-Z]+#", $pass)) {
$errors[] = "Password must include at least one letter!";
}
return (empty($errors));
}
function buttonGreyed($pass,$Checkpass){
return CheckStrength($pass) && CheckSame($pass, $Checkpass);
}
好了,所以我說用javascript ungrey下面的代碼/灰色按鈕,但它似乎沒有做任何事情,不知道它的厲害writen或什麼IM很新SRY。
$greyed = buttonGreyed($pass, $CheckPass);
<script type="text/javascript">
function greybutton(CreateButton) {
var php_var = "<?php echo $greyed; ?>";
if php_var = true {
Createbutton.disabled = false
}
else{
CreateButton.disabled = true
}
}
你說得對,Javascript是切換按鈕顏色的方法。我建議使用
@MarkBellamy我不知道這會有所幫助,只要點擊按鈕,該表單就可以執行sql代碼。想想幾乎已經認識到,生病了,我的答案在一點點。 –
允許用戶使用他們所需的[密碼/短語](https://xkcd.com/936/)。 [不要限制密碼。](http://jayblanchard.net/security_fail_passwords。html) –