How do i prevent the error-message from showing before the 'submit'-button is clicked?
For some reason the content of 'else'-statement is visible on pageload - the message "NO" should only appear after typing something else than 'a' in this.. what am i doing wrong?
<form method="POST">
<input type="text" class="textfield" id="cursor" name="pass">
<input type="submit" class="button" name="submit" value="OK">
</form>
<?php
$pass = $_POST['pass'];
if($pass == 'a') {
echo "YES";
}
else{
echo "NO";
}
?>
Add this PHP code:
<?php
if(isset($_POST['pass'])) {
// your check here
}
?>
Test to see if the submit button is in the submitted data.
if (isset( $_POST['submit'] )) {
<form method="POST">
<input type="text" class="textfield" id="cursor" name="pass">
<input type="submit" class="button" name="submit" value="OK">
</form>
<?php
$pass = $_POST['pass'];
//You need to check if the form is submitted
if($_POST['submit']){
if(isset($pass) && !empty($pass) && $pass == 'a') {
echo "YES";
}
else{
echo "NO";
}
?>