Skip to content

Instantly share code, notes, and snippets.

@walterdavis
Created June 16, 2012 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterdavis/2939426 to your computer and use it in GitHub Desktop.
Save walterdavis/2939426 to your computer and use it in GitHub Desktop.
<?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