I have the following code that checks if a password is strong enough and matching and returns a boolean value. Is there a way to use this value to ungrey a button that is by default grey if the value returned is true? I assume you would do this in javascript but im not sure.
<?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);
}
Ok so I added the following code using javascript to ungrey/grey the button but it doesnt seem to do anything not sure if its badly writen or what im very new 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
}
}