0 votes
11.1k views
in General by
I am trying to submit and get values from a form. There, it checks if the input mail is filled. Problem is, I'm seeing it submitted everytime even if value is not filled. 

Please see below codes.

<form name="testform" method="post" action="checkdata.php"> 
<input type="text" name="emailid"/> <br />
<input type="password" name="password"/><br />
<input type="submit"  value="submit"/>
</form>

and on checkdata.php
if (isset($_POST["mailid"])) {
    echo "Yes, mailid was submitted";    
}else{  
    echo "No, mailid was not submitted";
}
What am I doing wrong here? 

1 Answer

0 votes
by

When you submit that form, $_POST is always set, same in case of $_POST["mailid"]

The variable is set, but it is blank. So you need to check if it is blank also.

if (isset($_POST["mailid"]) && !empty($_POST["mailid"])) {
    echo "Yes, mailid was submitted";
}else{  
    echo "No, mailid was not submitted";
}

Related questions

0 votes
1 answer 1.7k views
asked May 26, 2016 in General by Cyan
0 votes
1 answer 694 views
asked Jan 23, 2022 in General by Sarath
0 votes
1 answer 648 views
asked Oct 29, 2021 in General by anonymous
0 votes
1 answer 803 views
0 votes
1 answer 630 views
asked Oct 29, 2021 in General by anonymous
0 votes
0 answers 3.6k views
...