PHP code example of softxpert / magento1-validator

1. Go to this page and download the library: Download softxpert/magento1-validator 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/ */

    

softxpert / magento1-validator example snippets


// Create an instance of the validator model
/** @var Softxpert_Validator_Model_Validator $validator */
$vaidator = Mage::getModel('softxpert_validator/validator');
// Preparing validator with data and rules arrays
$data  = $this->getRequest->getParams();
$rules = [
    'username' => '

$data = [
    'banner' => [
        'url'       => 'some value',
        'link_type' => 'cutom',
        'roles'     => ['admin', 'user'],
        'words'  => [
            [
                'letters' => 789
            ],
            [
                'letters' => 'string'
            ]
        ]
    ]
];

$rules = [
    'banner.url'     => 'string',
    'banner.url'     => 'string|in:valid,custom',
    'banner.roles.*' => 'string',
    'banner.words.*.letters' => 'string',
];

/** @var Softxpert_Validator_Model_Validator $validator */
$vaidator = Mage::getModel('softxpert_validator/validator');
$validator->validate($data, $rules)->redirectOnFailure();

/**
 * @param  array $data
 * @param  array $rules
 * @return Softxpert_Validator_Model_Validator
 */
public function validate($data, $rules)

/**
 * @param  string|null $fieldName
 * @return bool
 */
public function isValid($fieldName = null)

/**
 * @param  string|null $fieldName
 * @return bool
 */
public function fails($fieldName = null)

/**
 * @return array
 */
public function getMessages()

/**
 * @return string
 */
public function getMessagesTemplate()

/**
 * @param  bool $wantsJson
 * @param  string|null $redirectTo
 */
public function redirectOnFailure($wantsJson = false, $redirectTo = null)

/**
 * @param  bool $flag
 * @return $this
 */
public function noChain($flag = true)