1. Go to this page and download the library: Download progphil1337/php-forms 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/ */
progphil1337 / php-forms example snippets
use ProgPhil1337\Forms\Element\Input;
use ProgPhil1337\Forms\Element\Radio;
use ProgPhil1337\Forms\Element\Select;
use ProgPhil1337\Forms\Enum\InputType;
use ProgPhil1337\Forms\Form;
use ProgPhil1337\Forms\Validation\Validator\MaxLength;
use ProgPhil1337\Forms\Validation\Validator\MinLength;
use ProgPhil1337\Forms\Validation\Validator\IsRequired;
use ProgPhil1337\Forms\Enum\RequestMethod;
class ExampleForm extends Form
{
public function __construct()
{
parent::__construct('example-form', RequestMethod::POST);
}
protected function build(): void
{
$username = new Input('username', InputType::TEXT, 'Username');
$username->addValidator(new MaxLength(1));
$username->addValidator(new MinLength(1));
$username->addValidator(new IsRequired(true));
$this->add($username);
$mail = new Input('mail', InputType::EMAIL, 'E-Mail');
$this->add($mail);
$radio = new Radio('language', [
'php' => 'PHP',
'csharp' => 'C-Sharp'
], 'Favorite Language');
$radio->setValue('php');
$this->add($radio);
$select = new Select('car', [
'volvo' => 'Volvo',
'vw' => 'VW',
'bmw' => 'BMW',
'audi' => 'Audi'
], 'Favorite car');
$select->setValue('audi'); // obviously
$this->add($select);
$this->submitButton('Speichern');
}
}