contenir/formbuilder

Framework-agnostic form-builder engine for Contenir CMS — runtime-editable form definitions, builder-form construction, server-side submission validation.

Maintainers

Package info

github.com/contenir/formbuilder

pkg:composer/contenir/formbuilder

Statistics

Installs: 3

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.2 2026-05-10 11:52 UTC

This package is auto-updated.

Last update: 2026-05-10 12:35:49 UTC


README

Framework-agnostic form-builder engine for Contenir CMS.

Provides the runtime-editable form-definition value objects, the registry of field types, the curated validator vocabulary, the conditional-visibility rule engine, and the build/submit services that turn a stored definition into a working Laminas\Form\Form and a validated submission.

This package is the pure-PHP core. It has no opinion about how form definitions are loaded (DB, JSON, hardcoded array — bring your own loader) or how submissions are stored (registrar pattern). Adapter packages such as contenir/formbuilder-laminas-mvc wire it into a host framework.

Install

composer require contenir/formbuilder

Optional but commonly paired:

  • contenir/storage — required for the file field type, passed in to FormSubmissionService.

Layout

src/
├── Definition/   value objects: FormDefinition, SectionDefinition,
│                 GroupDefinition, RowDefinition, FieldDefinition,
│                 ValidatorDefinition, NotificationDefinition,
│                 WebhookDefinition
├── FieldType/    FieldTypeRegistry + FieldTypeInterface + 17 built-in
│                 types (text, email, url, tel, number, date, time,
│                 datetime, select, multiselect, radio, checkbox,
│                 multicheckbox, textarea, file, hidden, content)
├── Validator/    ValidatorFactory — curated vocabulary mapping onto
│                 Laminas validators (StringLength, Between, Hostname,
│                 Regex, Identical, EmailAddress)
├── Conditional/  RuleEvaluator + ConditionalRulesParser
└── Service/      FormBuilderService, FormSubmissionService,
                  TokenReplacer, BuilderForm, SubmissionResult

Usage

use Contenir\FormBuilder\Definition\FormDefinition;
use Contenir\FormBuilder\FieldType\FieldTypeRegistry;
use Contenir\FormBuilder\Service\FormBuilderService;
use Contenir\FormBuilder\Service\FormSubmissionService;
use Contenir\FormBuilder\Validator\ValidatorFactory;

$registry = new FieldTypeRegistry();
$validators = new ValidatorFactory();

$builder = new FormBuilderService($registry, $validators);
$form    = $builder->build($definition);  // Laminas\Form\Form

$service = new FormSubmissionService($builder);
$service->attach($yourPersistenceObserver);
$result = $service->submit($definition, $_POST, $_FILES, [
    'ip'      => $_SERVER['REMOTE_ADDR'] ?? null,
    'user_id' => null,
    'meta'    => [],
]);

License

MIT.