0 votes
11.3k 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.9k views
asked May 26, 2016 in General by Cyan
0 votes
1 answer 1.1k views
asked Jan 23, 2022 in General by Sarath
0 votes
1 answer 1.0k views
asked Oct 29, 2021 in General by anonymous
0 votes
1 answer 1.2k views
0 votes
1 answer 972 views
asked Oct 29, 2021 in General by anonymous
0 votes
0 answers 4.0k views
...