I'm wondering how to setup a checkbox that says...
I agree to the terms and conditions
But the users can only click the sign up button if the checkbox has been clicked.
Here is most of my whole registration page code.
<body class="login-body">
<div class="container">
<form class="form-signin" action="/register" method="POST">
<h2 class="form-signin-heading"><?php echo $website;?></h2>
<div class="login-wrap">
<?php
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['confirmpassword']) && isset($_POST['email'])) {
$username = mysqli_real_escape_string($con, $_POST['username']);
$password = mysqli_real_escape_string($con, md5($_POST['password']));
$confirmpassword = mysqli_real_escape_string($con, md5($_POST['confirmpassword']));
$email = mysqli_real_escape_string($con, $_POST['email']);
if($password != $confirmpassword) {
echo "<div class=\"alert alert-danger\">The passwords you entered do not match.</div>";
$error = 'yes';
}
if(strlen($_POST['password']) < 8) {
echo "<div class=\"alert alert-danger\">Your password must be atleast 8 characters!</div>";
$error = 'yes';
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = 'yes';
echo "<div class=\"alert alert-danger\">The email you entered is invalid.</div>";
}
$result = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username'") or die(mysqli_error($con));
if (mysqli_num_rows($result) > 0) {
$error = 'yes';
echo "<div class=\"alert alert-danger\">This username already exists.</div>";
}
$result = mysqli_query($con, "SELECT * FROM `users` WHERE `email` = '$email'") or die(mysqli_error($con));
if (mysqli_num_rows($result) > 0) {
$error = 'yes';
echo "<div class=\"alert alert-danger\">The email you entered can not be used.</div>";
}
$ip = mysqli_real_escape_string($con, $_SERVER['REMOTE_ADDR']);
$date = date('Y-m-d');
if ($error != 'yes') {
mysqli_query($con, "INSERT INTO `users` (`username`, `password`, `email`, `date`, `ip`) VALUES ('$username', '$password', '$email', '$date', '$ip')") or die(mysqli_error($con));
header("Location: /login?action=registered");
}
}
?>
<input type="text" id="username" name="username" class="form-control" placeholder="Username" value="<?php echo $_POST['username'] ?>" autofocus>
<input type="password" id="password" name="password" class="form-control" placeholder="Password">
<input type="password" id="confirmpassword" name="confirmpassword" class="form-control" placeholder="Confirm Password">
<input type="text" id="email" name="email" class="form-control" placeholder="Email" value="<?php echo $_POST['email'] ?>">
<button class="btn btn-lg btn-login btn-block" type="submit">Register</button>
</form>
<div class="registration">
Already have an account? 
<a class="" href="/login">
Sign In
</a>
</div>
</div>
</div><!-- end .container -->
Aucun commentaire:
Enregistrer un commentaire