Skip to content
/ tforms Public

TForms is a flexible forms validation library for PHP API project.

License

Notifications You must be signed in to change notification settings

wudege/tforms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tforms

TForms is a flexible forms validation library for PHP API project.

Software License Latest Stable Version Total Downloads Twitter URL

INSTALL

  • Use the composer command or the composer.json file. That's the recommend way. And the SDK is here wudege/tforms
$ composer require wudege/tforms

USAGE

require __DIR__ . '/../vendor/autoload.php';

class UserEditForm extends \TForms\Form
{
    const GENDER_MALE   = 1;
    const GENDER_FEMALE = 0;

    public $username;
    public $email;
    public $age;
    public $gender;
    public $blog;

    /**
     *
     * @author wudege <hi@wudege.me>
     * @return array
     */
    public function attributeNames()
    {
        return [
            'username',
            'email',
            'age',
            'gender',
            'blog',
        ];
    }

    public function attributeLabels()
    {
        return [
            'username',
            'email',
            'age',
            'gender',
            'blog',
        ];
    }

    public function rules()
    {
        return [
            ['username, email, age, gender, blog', 'required'],
            ['username', 'length', 'min' => 4, 'max' => 32],
            ['email', 'email'],
            ['age', 'numerical', 'min' => 18, 'max' => 28, 'integerOnly' => true],
            ['gender', 'in', 'range' => [self::GENDER_MALE, self::GENDER_FEMALE]],
            ['blog', 'url'],
        ];
    }
}

$form             = new UserEditForm();
$form->attributes = [
    'username' => 'wudege',
    'email'    => 'hi@wudege.me',
    'age'      => 20,
    'gender'   => 1,
    'blog'     => 'https://wudege.me',
];

try {
    $form->validate();
} catch (\TForms\Exception\ValidationException $e) {
    die($e->getMessage());
}
die('done');

TEST

$ ./vendor/bin/phpunit tests/TForms/Tests 

LICENSE

The MIT License (MIT). License File.

About

TForms is a flexible forms validation library for PHP API project.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages