PHP code example of sunnyflail / forms

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

    

sunnyflail / forms example snippets


use SunnyFlail\Forms\Form\FormElement;
use SunnyFlail\Forms\Interfaces\IFormBuilder;

class ConcreteForm extends FormElement
{

    public function build(IFormBuilder $builder)
    {
        (...)
    }

}

$builder->add(new InputField('text'));

$objectCreator = new SunnyFlail\ObjectCreator\ObjectCreator();
$valueMapper = new SunnyFlail\Forms\Mappers\ValueMapper($objectCreator);
$valueProviderFactory = new SunnyFlail\Forms\Providers\ProviderFactory();

$builder = new SunnyFlail\Forms\Form\FormBuilder($valueMapper, $valueProviderFactory);

$concreteFormBuilder = $builder->buildForm(ConcreteForm::class);

if ($concreteFormBuilder->processForm($request)) {
    (...)
}

$values = $concreteFormBuilder->getProcessedData();

$concreteFormBuilder->addError('An error occurred!');

$input = new SunnyFlail\Forms\Fields\InputField();

$input = new SunnyFlail\Forms\Fields\EmailField();

$input = new SunnyFlail\Forms\Fields\PasswordField();

$input = new SunnyFlail\Forms\Fields\TextAreaField();

$input = new SunnyFlail\Forms\Fields\SelectField();

$input = new SunnyFlail\Forms\Fields\CheckBoxGroupField();

$input = new SunnyFlail\Forms\Fields\RadioGroupField();

$input = new SunnyFlail\Forms\Fields\RepeatedInputField();

$input = new SunnyFlail\Forms\Fields\ClassMappedField();