https://github.com/wudege/tforms
TForms is a flexible forms validation library for PHP API project.
https://github.com/wudege/tforms
form-validation forms tforms validation validations validator
Last synced: 29 days ago
JSON representation
TForms is a flexible forms validation library for PHP API project.
- Host: GitHub
- URL: https://github.com/wudege/tforms
- Owner: wudege
- License: mit
- Created: 2017-02-13T07:17:18.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-20T04:01:49.000Z (almost 9 years ago)
- Last Synced: 2025-08-13T11:36:37.540Z (6 months ago)
- Topics: form-validation, forms, tforms, validation, validations, validator
- Language: PHP
- Size: 35.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tforms
TForms is a flexible forms validation library for PHP API project.
[](LICENSE)
[](https://packagist.org/packages/wudege/tforms)
[](https://packagist.org/packages/wudege/tforms)
[](https://twitter.com/wudege)
## INSTALL
* Use the composer command or the composer.json file. That's the recommend way. And the SDK is here [`wudege/tforms`][install-packagist]
```bash
$ composer require wudege/tforms
```
## USAGE
```php
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
* @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
``` bash
$ ./vendor/bin/phpunit tests/TForms/Tests
```
## LICENSE
The MIT License (MIT). [License File](https://github.com/wudege/tforms/blob/master/LICENSE).
[packagist]: http://packagist.org
[install-packagist]: https://packagist.org/packages/wudege/tforms