PHP code example of ms100 / form-validation

1. Go to this page and download the library: Download ms100/form-validation 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/ */

    

ms100 / form-validation example snippets


    <?
        $rules = [
            [
                'field' => 'info[id]',//rules只会作用于info[id],不会作用于info的其他元素
                'label' => 'ID信息',
                'rules' => '      $_POST = ['info' => []]; //不能通过验证,因为如果存在 info,则必须存在 info[id]
    

    <?
        //上传图片的验证配置
        $rules = [
            [
                'field' => 'image',
                'label' => '图片',
                'rules' => ']',
            ],
            [
                'field' => 'image[size]',
                'label' => '图片',
                'rules' => 'is_int|file_size_max[2MB]',//这里一定要写 is_int
            ],
            [
                'field' => 'image[error]',
                'label' => '图片',
                'rules' => 'is_int|file_upload_error[0]',//这里一定要写 is_int
            ],
            /*[
                'field' => 'image[tmp_name]',
                'label' => '图片',
                'rules' => 'image_pixel_min[1,1]|image_pixel_max[1000,1000]||valid_image[image[name]]',
            ],*/
        ];
    

    <?
        $rules = [
            [
                'field' => 'like',
                'label' => '爱好',
                'rules' => 'is_set|is_array',
            ],
            [
                'field' => 'like[]',
                'label' => '爱好信息',
                'rules' => '=> '通过
        
        $_POST = [
            'like' => [
                'aaa', //不能通过,元素必须是数组
                ['name' => 'football', 'level' => 'normal'], //通过
                ['name' => 'basketball', 'des' => 'haha'], //不能通过,因为没有level字段
                ['name' => 'sing', 'level' => 'normal', 'des' => 'song'], //通过
            ],
        ];

    

    <?
        $rules = [
            [
                'field' => 'name[a]',
                'label' => 'A',
                'rules' => 'ed|min_length[5]',
            ],
            [
                'field' => 'name[b]',
                'label' => 'B',
                'rules' => '