I have a variable pulled from a WordPress meta array - $vCode
.
This variable is a 5 digit number.
On the page front-end I have an HTML form requesting a code to be entered and a submit button.
Upon submit I want the entered code to be checked against $vCode
and display either "success" or "fail" if it matches or not.
- Should I be using an HTML form here or PHP?
- What is the best way to run the check without leaving the page?
This is what I have so far:
$vCode = 11111; $message = ""; if(!isset($_POST['submitbutton'])){ $message = "not submitted"; } elseif ((isset($_POST['submitbutton'])) && ($input = $vCode)) {//check if form was submitted $input = $_POST['vCode']; //get input text $message = "Success! You entered: ".$input; } elseif ((isset($_POST['submitbutton'])) && ($input != $vCode)) { $input = $_POST['vCode']; $message = "OOps"; } ?> <form action="" method="post"> <?php echo $message; ?> Validation Code:<br> <input type="number" name="vCode" value=""><br> <input type="submit" name="submitbutton" value="Submit"> </form>
This is always showing that I entered the correct number?
Thanks as always.