PHP code example of erdalceylan / php-dynamic-form

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

    

erdalceylan / php-dynamic-form example snippets




use \DynamicForm\Form,
    \DynamicForm\Fields\CheckBox,
    \DynamicForm\Fields\Radio,
    \DynamicForm\Fields\Select,
    \DynamicForm\Fields\Range,
    \DynamicForm\Fields\Text,
    \DynamicForm\Fields\Slide,
    \DynamicForm\Fields\TextArea;

use \DynamicForm\Fields\Items\CheckBoxItem,
    \DynamicForm\Fields\Items\RadioItem,
    \DynamicForm\Fields\Items\SelectItem,
    \DynamicForm\Fields\Items\RangeItem;

use \DynamicForm\Fields\Validators\Inclusion,
    \DynamicForm\Fields\Validators\Required,
    \DynamicForm\Fields\Validators\Email,
    \DynamicForm\Fields\Validators\Date,
    \DynamicForm\Fields\Validators\Regex,
    \DynamicForm\Fields\Validators\StringLength;

class TestForm extends Form
{
    public function __construct()
    {
        $this->setName("form1")
            ->setTitle("My EXAMPLE FORM");

        ## CheckBox fields
        $checkBoxField = (new CheckBox())
            ->setName("checkBox1")
            ->setLabel("any check box 1");
        
        $checkBoxField->addValidators([
            new Inclusion("data error"),
            new Required("(new SelectItem())
                ->setText("any select item label-".$i)
                ->setValue($i);

            $selectField->prepend($selectValue);
        }

        ##Range fields
        $rangeField = (new Range())
            ->setName("range1")
            ->setLabel("any range")
            ->setMin(0)
            ->setMax(100)
            ->setValues(new RangeItem(30, 60));
        
        $rangeField
            ->addValidator(new Inclusion("data error"));

        ##Text fields
        $textField = (new Text())
            ->setName("text1")
            ->setLabel("email")
            ->setValue("[email protected]");
        
        $textField->addValidator(new Email("error email"));

        ##Text fields
        $textFieldDate = (new Text())
            ->setName("date")
            ->setLabel("date of birth")
            ->setValue("");
        
        $textFieldDate
            ->addValidator(new Date("-35 year", "-18 year","year error"))
            ->addValidator(new Required("date is 
javascript
{
    "an/php-dynamic-form": "dev-master"
    }
}