The package helps with implementing data entry forms.

dev-master / 1.0.x-dev 2021-09-07 20:59 UTC

This package is auto-updated.

Last update: 2021-09-07 20:59:11 UTC



Yii Form

The package helps with implementing data entry forms.

Latest Stable Version Total Downloads Build status Scrutinizer Code Quality Code Coverage Mutation testing badge static analysis type-coverage


The package could be installed via composer:

composer require yiisoft/form


You must create your form model by extending the abstract form class, defining all the private properties with their respective typehint.

Example: LoginForm.php



namespace App\Form;

use Yiisoft\Form\FormModel;
use Yiisoft\Validator\Rule\Email;
use Yiisoft\Validator\Rule\Required;
use Yiisoft\Validator\Rule\HasLength;

class LoginForm extends FormModel
    /** Define properties with TypeHint */
    private ?string $login = null;
    private ?string $password = null;
    private bool $rememberMe = false;

    /** Getters properties */
    public function getLogin(): ?string
        return $this->login;

    public function getPassword(): ?string
        return $this->password;

    public function getRememberMe(): bool
        return $this->rememberMe;

    /** Setters properties */
    public function login(string $value): void
        $this->login = $value;

    public function password(string $value): void
        $this->password = $value;

    public function rememberMe(bool $value): void
        $this->rememberMe = $value;

    /** Define labels */
    public function attributeLabels(): array
        return [
            'login' => 'Login:',
            'password' => 'Password:',
            'rememberMe' => 'remember Me:'

    /** Define form name */
    public function formName(): string
        return 'LoginForm';

    /** Add rules */
    public function rules(): array
        return [
            'login' => $this->loginRules()

    /** Define login rules */
    private function loginRules(): array
        return [
            new Required(),
            (new HasLength())
            ->tooShortMessage('Is too short.')
            ->tooLongMessage('Is too long.'),
            new Email()

Unit testing

The package is tested with PHPUnit. To run tests:


Mutation testing

The package tests are checked with Infection mutation framework. To run it:


Static analysis

The code is statically analyzed with Psalm. To run static analysis:


Support the project

Open Collective

Follow updates

Official website Twitter Telegram Facebook Slack


The Yii Form is free software. It is released under the terms of the BSD License. Please see LICENSE for more information.

Maintained by Yii Software.