Skip to content

Instantly share code, notes, and snippets.

@jabaltorres
Created May 10, 2019 04:05
Show Gist options
  • Save jabaltorres/c2cf6352c6ae0940ed8c7d7fc7908f0b to your computer and use it in GitHub Desktop.
Save jabaltorres/c2cf6352c6ae0940ed8c7d7fc7908f0b to your computer and use it in GitHub Desktop.
<?php
// JT Test - being used on demos/forms/forms.php
function validate_jt_test_form($jtMessage) {
$errors = [];
if(is_blank($jtMessage['name'])) {
$errors[] = "Name cannot be blank.";
} elseif(!has_length($jtMessage['name'], ['min' => 2, 'max' => 255])) {
$errors[] = "Name must be between 2 and 255 characters.";
}
if (!has_valid_email_format($jtMessage['email'])){
$errors[] = "Invalid email format";
}
if(is_blank($jtMessage['message'])) {
$errors[] = "Message cannot be blank.";
} elseif(!has_length($jtMessage['message'], ['min' => 10, 'max' => 255])) {
$errors[] = "Message must be between 10 and 255 characters.";
}
if(!empty($errors)) {
return $errors;
}
// Testing the return statement.
echo '<ul>';
foreach($jtMessage as $jtMessageItem) {
echo "<li>" . h($jtMessageItem) . "</li>";
}
echo '</ul>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment