cleanup and sync
This commit is contained in:
+108
-39
@@ -1,53 +1,122 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file provides functions for validating form input data. For any given
|
||||
* field in an associative array, provide an array of validation requirements.
|
||||
* This is to enable modular data fields while ensuring data integrity and
|
||||
* safety from SQL injection.
|
||||
* Author: Joshua Ashton <me@joshashton.dev>
|
||||
* Date: 06 March 2025
|
||||
* Version: v0.1.0
|
||||
*
|
||||
* Each function accepts at least an input string, and will return either true
|
||||
* or false. It is up to the client to interpret that and create error messages
|
||||
* and ensure data format consistency accordingly.
|
||||
*
|
||||
* EXAMPLE CLIENT DATA IMPLEMENTATION
|
||||
* A data format standard for easily creating forms with input validation.
|
||||
*
|
||||
* $standard_fields = [
|
||||
* 'ca-username' => [
|
||||
* // Placeholder text
|
||||
* 'e.g., jsmith',
|
||||
*
|
||||
* // Validation requirements
|
||||
* [
|
||||
* 'no_spaces',
|
||||
* 'checkSQL',
|
||||
* ],
|
||||
* ],
|
||||
* ];
|
||||
* This file provides functions for validating form input data. For any given
|
||||
* field in an associative array, provide an array of validation requirements.
|
||||
* This is to enable modular data fields while ensuring data integrity and
|
||||
* safety from SQL injection.
|
||||
*
|
||||
* EXAMPLE CLIENT IMPLEMENTATION
|
||||
*
|
||||
* function validate($standard_fields, $admin_fields) {
|
||||
* include('includes/input_validation.php');
|
||||
* $error = '';
|
||||
* foreach($standard_fields as $field => $arr) {
|
||||
* // Get the requirements from the associative array.
|
||||
* $validationRequirements = $arr[1];
|
||||
* Each function accepts at least an input string, and will return either true
|
||||
* or false. It is up to the client to interpret that and create error messages
|
||||
* and ensure data format consistency accordingly.
|
||||
*
|
||||
* foreach($validationRequirements as $validReq) {
|
||||
* switch($validReq) {
|
||||
* case 'no_spaces':
|
||||
* if(no_spaces($_POST[$field])) {
|
||||
* $error .= '<p>' . $field . ' does not allow spaces.</p>';
|
||||
* }
|
||||
* break;
|
||||
* default:
|
||||
* $error .= '<p>Something went wrong...</p>';
|
||||
* break;
|
||||
* }
|
||||
*
|
||||
* *****************************************************************************
|
||||
*
|
||||
*
|
||||
* EXAMPLE LOGIN DATA IMPLEMENTATION
|
||||
*
|
||||
*
|
||||
* $login_fields = [
|
||||
* 'method' => 'post',
|
||||
* 'action' => 'process.php?action=login',
|
||||
* 'login_username' => [
|
||||
* 'label' => 'username',
|
||||
* 'type' => 'text',
|
||||
* 'placeholder' => 'e.g., jsmith',
|
||||
* 'validators' => [
|
||||
* 'no_spaces',
|
||||
* 'check_sql',
|
||||
* ],
|
||||
* ],
|
||||
*
|
||||
* 'login_password' => [
|
||||
* 'label' => 'password',
|
||||
* 'type' => 'password',
|
||||
* 'placeholder' => '',
|
||||
* 'validators' => [
|
||||
* 'no_spaces',
|
||||
* 'pw_strength',
|
||||
* 'no_backslash',
|
||||
* 'check_sql',
|
||||
* ],
|
||||
* ],
|
||||
* ];
|
||||
*
|
||||
*
|
||||
* *****************************************************************************
|
||||
*
|
||||
*
|
||||
* CLIENT VALIDATION IMPLEMENTATION
|
||||
*
|
||||
*
|
||||
* function validate($input, $validators)
|
||||
* {
|
||||
* include_once ('includes/input_validation.php');
|
||||
*
|
||||
* foreach ($validators as $v) {
|
||||
* switch ($v) {
|
||||
* case 'no_spaces':
|
||||
* if (!no_spaces($input))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'no_digits':
|
||||
* if (!no_digits($input))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'no_backslash':
|
||||
* if (!no_backslash($input))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'no_special':
|
||||
* if (!no_special($input))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'only_digits':
|
||||
* if (!only_digits($input))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'only_digits_x':
|
||||
* if (!only_digits_x($input, 5))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'only_letters':
|
||||
* if (!only_letters($input))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'only_letters_x':
|
||||
* if (!only_letters_x($input, 5))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'valid_email':
|
||||
* if (!valid_email($input))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'valid_phone':
|
||||
* if (!valid_phone($input))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'pw_strength':
|
||||
* if (!pw_strength($input))
|
||||
* return false;
|
||||
* break;
|
||||
* case 'check_sql':
|
||||
* if (check_sql($input))
|
||||
* return false;
|
||||
* break;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* return true;
|
||||
* }
|
||||
*/
|
||||
|
||||
function no_spaces($input)
|
||||
|
||||
Reference in New Issue
Block a user