I am new to the web developing world.Please bare w/ me for having some mistakes and insufficient knowledge.
I'm trying to study the validation process of a users input. Below is my Code:
<?php
if($_POST['formSubmit'] == "Search")
{
$errorMessage = "";
if(empty($_POST['formName']))
{
$errorMessage .= "<li>No Input</li>";
}
$varName = $_POST['formName'];
if(!empty($errorMessage))
{
echo("<p>There was an error with your form:</p>\n");
echo("<ul>" . $errorMessage . "</ul>\n");
}
}
?>
<form action="index.php" method="post">
<input type="text" name="formName" value="<?=$varName;?>">
<input type="Submit" name="formSubmit" value=" Search">
</form>
What I think should happen is when the user click the search button without inputting anything an error message will pop-up, but I don't understand why its not responding or echoing the error message, i've check the names and values but Alas, Appreciate all the help/suggestions you could give tnx.
Thanks for the reply everyone, got it into working ^_^
$_POST['formSubmit']in aifand for any reason someone doesn't pass any parameter with that name it will pop a warning. To avoid this you can check if any value was passed or not before comparing it usingisset()