Created
November 15, 2020 16:24
-
-
Save alfintechcomputer/d48e4f9da70ecc2473ea6bec1be046c6 to your computer and use it in GitHub Desktop.
HTML Forms using PHP
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 has_presence($value) { | |
return isset($value) and $value !== ''; | |
} | |
function max_length($value, $max) { | |
return strlen($value) <= $max; | |
} | |
function min_length($value, $min) { | |
return strlen($value) >= $min; | |
} | |
function has_inclusion($value, $set) { | |
return in_array($value, $set); | |
} | |
function form_errors($errors = array()) { | |
$output = ''; | |
if(!empty($errors)){ | |
$output .= '<div class="alert alert-danger">'; | |
$output .= 'You might need to fix a few things!<br>'; | |
$output .= '<ul>'; | |
foreach($errors as $key => $error) { | |
$output .= '<li>'. $error .'</li>'; | |
} | |
$output .= '</ul>'; | |
$output .= '</div>'; | |
} | |
return $output; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment