PHP code example of web-complete / form

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

    

web-complete / form example snippets


[
    [field, filter, params]
]

[
    [field, validator, params, message]
]

[
    ['name', 'string', ['min' => 3]],
    ['data.nested.field', 'string', ['min' => 3]],
    ['age'], // this field is considered as safe
]

    public function __construct(
        $rules = null,
        $filters = null,
        $validatorsObject = null,
        $filtersObject = null
    )

class MyForm1 extends \WebComplete\form\AbstractForm
{
    
    protected function filters()
    {
        return [
            [['first_name', 'last_name'], 'capitalize'],
            ['description', 'stripTags'],
            ['content', 'stripJs'],
            ['data.nested.field', 'trim'],
            ['email', 'replace', ['pattern' => 'email.com', 'to' => 'gmail.com']],
            ['*', 'trim'],
        ];
    }

    protected function rules()
    {
        return [
            [['description', 'label'], ], // safe fields (no validation)
            [['name', 'email'], 'value, $params, AbstractForm $form)
    {
        ...
        return true;
    }
    
    protected function validateToken($value, $params, AbstractForm $form)
    {
        ...
        return true;
    }
    
}

$form = new MyForm([], [], new Validators(), new Filters());
$form->setData($_POST);
if($form->validate()) {
    $filteredData = $form->getData();
    ...
}

$form = new FastForm([['name', 'm->validate()) {
    $filteredData = $form->getData();
    ...
}
else {
    $form->getErrors();
//    $form->getErrors('name');
//    $form->getFirstErrors();
//    $form->hasErrors();
    ...
}

abstract class MyAbstractForm extends \WebComplete\form\AbstractForm
{

    protected function filters()
    {
        return [
            ['*', 'trim'] 
        ];
    }

    public function __construct($rules = [], $filters = [])
    {
        parent::__construct($rules, $filters, new Validators(), new Filters();
    }
    
}