Hello,
I have a form which I am using simple php validation on.
At the end you can find the error array code.
Some of the options are in a drop-down list/menu
Although the form checks string length as required on _post, when the page is refreshed the input value (on dropdowns) will disappear, which will become quite frustrating having to enter the info each time, despite the error message not telling you it is missing.
Is there a way to maintain the previous input? Or perhaps there is a better way to check for errors?
if(isset($_POST['Submitted'])) {
$Errors = Array();
if(strlen(trim($_POST['name'])) <3 ) $Errors[] = "Please check your name is correct";
if(!preg_match("/[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9]{2,4}/",$_POST['email'])) $Errors[] = "please check your email address";
if(strlen($_POST['group_size']) >4) $Errors[] = "How many people?";
if(strlen($_POST['rooms']) >4) $Errors[] = "How many rooms?";
if(strlen($_POST['nights']) >4) $Errors[] = "How many nights?";
if(!trim($_POST['comment'])) $Errors[] = "Please add some more comments";
if(strtolower(trim($_POST['antispam'])) != "xxxxxx") $Errors[] = "Spam check should be xxxxxx";
if(!count($Errors)) {
You can look at the html at http://yabbox.com/form-php.php