PHP code example of simon-ugorji / octavalidate-php

1. Go to this page and download the library: Download simon-ugorji/octavalidate-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

simon-ugorji / octavalidate-php example snippets




use Validate\octaValidate;

$myForm = new octaValidate('FORM_ID', 'CONFIG_OPTIONS');

//equire 'src/Validate.php';

use Validate\octaValidate;

//create new instance
$myForm = new octaValidate('FORM_ID', 'CONFIG_OPTIONS');

//syntax for defining validation rules
$valRules = array(
  "FORM_INPUT_NAME" => array(
    ["RULE_TITLE", "CUSTOM_ERROR_MESSAGE"]
  )
);

/* If you don't provide a custom error message, 
the script will use the default one available
*/

//define rules for each form input name
$valRules = array(
  "uname" => array(
    ["R", "Your username is 

   //validate $_POST fields
   $myForm->validateFields($valRules, $_POST);

   //validate $_GET fields
   $myForm->validateFields($valRules, $_GET);
   

$myForm->customRule($RULE_TITLE, $REG_EXP, $ERROR_TEXT);

//equire 'src/Validate.php';

use Validate\octaValidate;

//create new instance
$myForm = new octaValidate('my_form');

//custom password validation
$rule_title = 'PASS';
$reg_exp = '/12345/';
$err_txt = "Please enter 12345";
//build the rule
$myForm->customRule($rule_title, $reg_exp, $err_txt);

//provide the rule title when defining validation rules
$valRules = array(
    "password" => array(
        ["PASS"]
    )
);

$RULES = array(
    "RULE_TITLE" => ['REG_EXP', 'CUSTOM_ERROR_MESSAGE']
);
$myForm->moreCustomRules($RULES);

//equire 'src/Validate.php';

use Validate\octaValidate;

$myForm = new octaValidate('my_form');

//custom username & password validation
$rules = array(
    "PASS" => ['/12345/', "Please enter 12345"],
    "UNAME" => ['/simon/', "Please enter simon"]
);

//build the rule
$myForm->moreCustomRules($rules);

//provide the rule title when defining validation
$valRules = array(
    "username" => array( 
        ["UNAME"] 
    ),
    "password" => array( 
        ["PASS"] 
    )
);

//syntax
$valRules = array(
  "FORM_INPUT_NAME" => array(
    ["ATTRIBUTE_TITLE", "VALUE", "CUSTOM_ERROR_MESSAGE"]
  )
);

//sample validation
$valRules = array(
  "username" => array(
    ["R", "Your username is array(
    ["R", "Your age is 

//sample validation
$valRules = array(
  "password" => array(
    ["R", "Your password is 

//sample validation
$formRules = array(
    //single file upload
    "file" => array(
        ["R"],
        ["ACCEPT", ".mp3, .ogg"],
        ["MAXSIZE", "5mb"]
    ),
    //multiple files upload
    "files" => array(
        ["R"],
        ["ACCEPT-MIME", "image/*"],
        ["MAXFILES", "5"],
        ["MAXSIZE", "50mb"]
    )
);

//equire 'src/Validate.php';

use Validate\octaValidate;

//set configuration
$options = array(
  "stripTags" => true,
  "strictMode" => true,
  "strictWords" => ["null", "undefined"]
);
//create new instance
$myForm = new octaValidate('FORM_ID', $options);

//create instance of the function
$myForm = new octaValidate('FORM_ID');

$ composer