I am always running into situation where I need to check for empty fields or other validation that needs to have errors return to the user so they know what is wrong before submitting form. What I normally do, is as follows:
[php]<?php
$name = $_POST[‘name’];
$state = $_POST[‘state’];
$errors = array();
if(empty($name))
{
$errors[] = “You forgot to fill in your name!”;
}
if(empty($state))
{
$errors[] = “You forgot to fill in your state!”;
}
if(!empty($errors))
{
for($i = 0; $i < count($errors); $i++)
{
?>
<?
}
}
?>[/php]
Of course I do a little more formatting and such to make errors match the sites specific look and feel, but anyway, just was wondering if there was an easier way then writing an if statement for each field in the html form?
I haven’t thought of a better one or seen one as of yet.