PHP code example of codaxis / cakephp-multivalidation-behavior

1. Go to this page and download the library: Download codaxis/cakephp-multivalidation-behavior 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/ */

    

codaxis / cakephp-multivalidation-behavior example snippets


class User extends AppModel {

    public $actsAs = array(
        'MultiValidation.MultiValidation' => array(
            'types' => array(
                'enforceUsernameAndEmail' => array(
                    'username' => array(
                        'onlyAlpha' => array(
                            'rule' => 'alphaNumeric'
                        ),
                    ),
                    'email' =>
                        'validEmail' => array(
                            'rule' => 'email',
                            'ssword' => array(
            'minCharsAllowed' => array(
                'rule' => array('minLength', 4)
            )
        ),
    );
}

    // Add new username and email validation:
    $User->addValidation('enforceUsernameAndEmail');
    // $User->loadedValidation() would return array('enforceUsernameAndEmail')

    // Reset to default state:
    $User->resetValidation();
    // $User->loadedValidation() would return array('_default')

    // Load and set only the password validation:
    $User->loadValidation('enforcePassword');
    // $User->loadedValidation() would return array('enforcePassword')

    // Add the other validation type also:
    $User->addValidation('enforceUsernameAndEmail');
    // $User->loadedValidation() would return array('enforcePassword', 'enforceUsernameAndEmail')

    // Reset again to default state:
    $User->resetValidation();
    // $User->loadedValidation() would return array('_default')