Created
June 16, 2012 01:00
-
-
Save walterdavis/2939426 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function humanize($string){ | |
return ucwords(str_replace('_',' ',$string)); | |
} | |
if(isset($_POST['email'])){ //just picking this because you need something | |
$errors = array(); | |
foreach($_POST as $name => $field){ | |
if(substr($name, 0, 1) == '_'){ | |
continue; | |
}else{ | |
if(empty($field)){ | |
$errors[$name] = humanize($name) . ' cannot be blank'; | |
} | |
} | |
} | |
if(count($errors) > 0){ | |
$error_message = '<h3>The following ' . ((count($errors) == 1) ? 'field needs' : 'fields need') . ' your attention:</h3><ul>'; | |
foreach($errors as $error){ | |
$error_message .= '<li>' . $error . '</li>'; | |
} | |
$error_message .= '</ul>'; | |
}else{ | |
//do whatever you do to a successful form post here | |
header('Location: success.html'); | |
exit; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment