gcworld / formconfig
GCWorld Industries Form Config
Requires
- php: >=8.4
- composer/composer: ^2.9
- composer/installers: ^2.2
- gcworld/globals: ^4.0
- gcworld/interfaces: ^4.3.11
- kint-php/kint: >=1.1 <7.0
- symfony/yaml: ^6.0
- twig/twig: ^3.14
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12.0
- squizlabs/php_codesniffer: ^3.13
Suggests
- gcworld/orm: ^3.4.2
Provides
None
Conflicts
None
Replaces
None
- dev-master
- 4.0.0
- 3.11.24
- 3.11.23
- 3.11.22
- 3.11.21
- 3.11.20
- 3.11.19
- 3.11.18
- 3.11.17
- 3.11.16
- 3.11.15
- 3.11.14
- 3.11.13
- 3.11.12
- 3.11.11
- 3.11.10
- 3.11.9
- 3.11.8
- 3.11.7
- 3.11.6
- 3.11.5
- 3.11.4
- 3.11.3
- 3.11.2
- 3.11.1
- 3.11.0
- 3.10.7
- 3.10.6
- 3.10.5
- 3.10.4
- 3.10.3
- 3.10.2
- 3.10.1
- 3.10.0
- 3.9.22
- 3.9.21
- 3.9.20
- 3.9.19
- 3.9.18
- 3.9.17
- 3.9.16
- 3.9.15
- 3.9.14
- 3.9.13
- 3.9.12
- 3.9.11
- 3.9.10
- 3.9.9
- 3.9.8
- 3.9.7
- 3.9.6
- 3.9.5
- 3.9.4
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.8.5
- 3.8.4
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.6
- 3.6.5
- 3.6.4
- 3.6.3
- 3.6.2
- 3.6.1
- 3.6.0
- 3.5.1
- 3.5.0
- 3.4.27
- 3.4.26
- 3.4.25
- 3.4.24
- 3.4.23
- 3.4.22
- 3.4.21
- 3.4.19
- 3.4.18
- 3.4.17
- 3.4.16
- 3.4.15
- 3.4.14
- 3.4.13
- 3.4.12
- 3.4.11
- 3.4.10
- 3.4.9
- 3.4.8
- 3.4.7
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.9
- 3.3.8
- 3.3.7
- 3.3.6
- 3.3.5
- 3.3.4
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.2.7
- 3.2.6
- 3.2.5
- 3.2.4
- 3.2.3
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.5
- 3.1.4
- 3.1.3
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.12
- 3.0.11
- 3.0.10
- 3.0.9
- 3.0.8
- 3.0.7.1
- 3.0.7
- 3.0.6
- 3.0.5
- 3.0.4
- 3.0.3
- 3.0.2
- 3.0.1
- 3.0.0
- 2.1.8
- 2.1.7
- 2.1.6
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.9
- 2.0.8
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.4.3
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.8
- 1.3.7
- 1.3.6
- 1.3.5
- 1.3.4
- 1.3.3
- 1.3.2
- 1.3.1
- 1.3.0
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.0
This package is auto-updated.
Last update: 2026-09-17 18:28:42 UTC
README
FormConfig is a PHP library for defining forms as objects and rendering them with Twig. It provides reusable field types, repeatable field arrays, model and ORM metadata helpers, read-only transformations, configurable CSRF tokens, and a generated fluent field builder.
FormConfig renders form markup but does not persist submitted values or replace application-level validation and authorization.
Version
4.0.0
Requirements
- PHP 8.4 or newer
- Composer 2
- Twig 3
- A consumer-provided Bootstrap 3 frontend stack
Bootstrap 3 is currently the only implemented rendering mode. A Bootstrap 5 constant exists for future compatibility, but no Bootstrap 5 templates are registered or shipped.
Installation
Install the package from Packagist:
composer require gcworld/formconfig
The Composer post-autoload-dump hook performs two setup tasks:
- It creates
config/GCWorld_FormConfig.ymlin the consuming project when the file does not already exist. - It discovers the available field classes and generates the field registry
and fluent builder under
src/Generated/in the installed package.
Run composer dump-autoload after registering custom field groups or adding a
field class so the generated registry is refreshed.
Basic usage
<?php 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(), );
Fields can also be created generically when the type is selected dynamically:
use GCWorld\FormConfig\Fields\TextArea; $form->createField('notes') ->setType(TextArea::getKey()) ->setLabel('Notes');
The generated builder is preferable for normal application code because it provides discoverable methods for every registered field type.
Using an existing Twig environment
Applications that already own a Twig environment can register FormConfig's paths, functions, and tests directly:
use GCWorld\FormConfig\Core\Twig as FormConfigTwig; FormConfigTwig::mapAll($twigEnvironment); echo $twigEnvironment->render( '@form_config_BS3/forms/controller.twig', $form->getTwigArray(), );
mapAll() attaches the @form_config_BS3 namespace when the environment uses
Twig's FilesystemLoader. Custom form templates can be selected with
FormConfig::setTwigTemplate().
Values, requirements, and errors
Values, required levels, and validation errors can be applied by field name:
$form->setValues([ 'display_name' => 'Ada Lovelace', 'timezone' => 'America/Detroit', ]); $form->setRequirements([ 'display_name' => 2, ]); $form->setErrors([ 'display_name' => 'Display name is required.', 'form' => 'The form could not be saved.', ]);
Requirement level 0 suppresses a field, level 1 renders an optional field,
and values greater than 1 render the configured required indicator.
Errors whose keys do not match a field are rendered as unattributed form errors.
setValuesFromObject() reads matching getters and legacy model metadata.
setPropertiesFromObject() integrates with gcworld/interfaces ORM description
objects when that optional model layer is available.
Call makeReadOnly() to convert supported fields to their non-editable
representation before rendering.
Repeatable field arrays
createFieldArray() creates table, div, or Ionic-style groups containing one or
more rows:
$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');
Configuration
The installed config/GCWorld_FormConfig.yml supports these sections:
general: formMode: 'BS3' holdOn: false holdOnOptions: "HoldOnOptions" requiredIndicator: 2 debugging: enabled: false userCheckMethod: "\\App\\Debug\\FormDebug::isAllowed" csrf: enabled: false tokenNameMethod: "\\App\\Security\\Csrf::getTokenName" tokenValueMethod: "\\App\\Security\\Csrf::getTokenValue"
The optional forms section registers additional namespaces and directories
containing custom FieldInterface implementations. Its directories are resolved
relative to the consuming project during code generation.
Configuration is cached in process-level singletons. Applications using long-lived PHP workers should restart workers after changing FormConfig configuration.
CSRF responsibility
When CSRF is enabled and both token callbacks are configured, a hidden token field is added to each new form. The consuming application must still validate the submitted request:
use GCWorld\FormConfig\Core\CSRFController; CSRFController::get()->doCheck();
FormConfig does not call doCheck() automatically. Applications remain
responsible for invoking it at the correct point in their request lifecycle and
handling CSRFNotEnabledException or CSRFRequestFailedException.
Browser dependencies
Frontend assets are intentionally not installed through Composer. Consumers must load the dependencies required by the field types they use.
| Dependency | Used by |
|---|---|
| Bootstrap 3 | Form layout, panels, validation states, tables, buttons, and responsive classes |
| jQuery | All templates that emit interactive JavaScript |
| Select2 and a Bootstrap-compatible Select2 theme | Normal, HTML, grouped, and Ajax select fields |
CKEditor exposing the global CKEDITOR API |
CKEditor and CKEditorFull fields |
Bootstrap Datepicker or a compatible $.fn.datepicker plugin |
Date fields |
Spectrum or a compatible $.fn.spectrum plugin |
Color picker fields |
| Font Awesome | Help and navigation icons |
| HoldOn | Optional submit/loading overlays and Ajax-once loading overlays |
Exact asset versions are controlled by the consuming application. Before upgrading one of these libraries, verify the emitted initialization options and events against the FormConfig field types used by that application.
Several extension points intentionally render trusted strings with Twig's
raw filter, including HTML fields, labels, notices, headings, hooks, option
content, and submit-button overrides. Do not pass untrusted content to these
APIs without sanitizing it first.
The templates emit inline scripts. Applications enforcing Content Security Policy must account for those scripts or override the affected templates.
Local development
The supported local environment uses the public KongHack PHP 8.4 image:
./dc up -d ./dc exec php composer install ./dc exec php composer check ./dc down
The committed Compose configuration mounts only this repository. It does not
expose host SSH keys, Composer credentials, or host account databases to the
container. Developers who require private Composer authentication can copy
docker-compose.override.yml.example to the ignored
docker-compose.override.yml. The override exposes credentials to container
processes and should only be enabled when it is genuinely required.
Individual quality commands are also available:
./dc exec php composer lint ./dc exec php composer phpstan ./dc exec php composer phpcs ./dc exec php composer test
PHPStan is enforced at level 6. PHPCS enforces PSR-12 errors; advisory warnings such as line length do not fail the build.
Releases
Releases use bare semantic-version tags such as 3.11.23. Before tagging a
release:
- Add the release notes to the matching version section in
CHANGELOG.md. - Update
VERSIONand the value immediately below### Versionin this file. - Push the release commit and matching tag.
GitHub Actions validates the release metadata and complete PHP quality matrix
before creating the GitHub Release from CHANGELOG.md. Packagist is connected
to this repository and receives the published tag through the existing GitHub
integration.
Release tags must not be moved or reused.
License
FormConfig is open-source software licensed under the MIT License.