PHP code example of acfo / form-validation

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

    

acfo / form-validation example snippets


class LoginForm implements Form
{
    use FormImpl;
    
    private $email;
    private $password;
    
    public function __construct()
    {
        $this->email = new Email(Requirement::Required);
        $this->password = new Password(Requirement::Required);
    }
    
    public function getEmail()
    {
        return $this->email;
    }
    
    public function getPassword()
    {
        return $this->password();
    }
}

$loginForm = new LoginForm();

if (!$loginForm->validate($_POST)) {
    die('please do not try and feed me invalid data');
}
html
<form method="post" action="#">
    <div class="<?= $loginForm->getEmail()->getError()