PHP code example of gcworld / formconfig

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

    

gcworld / formconfig example snippets




use GCWorld\FormConfig\Core\Twig;
use GCWorld\FormConfig\Forms\FormConfig;

$form = (new FormConfig())
    ->setName('profile')
    ->setFormId('profile-form')
    ->setRenderForm('details')
    ->setRenderForms(['details' => 'Profile details'])
    ->setRenderUrlForm('/profile/details');

$form->getBuilder()
    ->createTextInput('display_name')
    ->setLabel('Display name')
    ->setValue('Ada Lovelace')
    ->setReqLevel(2);

$form->getBuilder()
    ->createSelectInput('timezone')
    ->setLabel('Time zone')
    ->setOptions([
        'America/Detroit' => 'Eastern Time',
        'America/Chicago' => 'Central Time',
    ]);

echo Twig::render(
    '@form_config_BS3/forms/controller.twig',
    $form->getTwigArray(),
);

echo Twig::render(
    '@form_config_BS5/forms/controller.twig',
    $form->getTwigArray(),
);

use GCWorld\FormConfig\Fields\TextArea;

$form->createField('notes')
    ->setType(TextArea::getKey())
    ->setLabel('Notes');

use GCWorld\FormConfig\Core\Twig as FormConfigTwig;

FormConfigTwig::mapAll($twigEnvironment);

echo $twigEnvironment->render(
    '@form_config_BS3/forms/controller.twig',
    $form->getTwigArray(),
);

$form->setValues([
    'display_name' => 'Ada Lovelace',
    'timezone' => 'America/Detroit',
]);

$form->setRequirements([
    'display_name' => 2,
]);

$form->setErrors([
    'display_name' => 'Display name is 

$items = $form->createFieldArray('items');
$items->addHeader('Description', 'col-sm-8');
$items->addHeader('Quantity', 'col-sm-4');

$items->createField('description')->setLabel('Description');
$items->createField('quantity')->setLabel('Quantity');

$items->bumpIndex();
$items->createField('description')->setLabel('Description');
$items->createField('quantity')->setLabel('Quantity');

use GCWorld\FormConfig\Core\CSRFController;

CSRFController::get()->doCheck();
console
./dc exec php composer lint
./dc exec php composer phpstan
./dc exec php composer phpcs
./dc exec php composer test