Accessible forms in Laravel and Symfony.
Add any notes here on problems to solve:
- What helpers do we need to make form generation easier?
- Page title Twig filter needs updating to detect number of form validation issues
- Twig in Barryvdh\Form appears to be installed separately to TwigBridge - is this an issue? Twig extension appears to be available for both.
- Can we automate adding the template paths, currently copy config/form.php across
- PHP 8.2+
You can install the package via Composer:
composer require studio24/accessible-formsDuring testing you can install this from a local copy via:
composer config repositories.local path "~/Sites/studio24/accessible-forms/"
composer require studio24/accessible-forms:dev-mainTo remove this after testing:
ddev composer config repositories.local --unset
ddev composer updateSee https://github.com/studio24/dev-playbook/blob/main/composer/testing-local-packages.md
Add the service provider to bootstrap/providers.php
return [
Barryvdh\Form\ServiceProvider::class,
];To enable TwigExtension in your normal Twig templates (not form twig templates at present) edit config/twigbridge.php
return [
'extensions' => [
'enabled' => [
'Studio24\AccessibleForms\Twig\AccessibleFormsExtension',
],
],
];Create a form class:
See https://symfony.com/doc/current/forms.html#creating-form-classes
The form processing workflow is:
- Display form
- Form submitted via POST request
- Form request data is validated
- If pass validation, do something, and redirect to success page
- If fail validation, redisplay form with validation messages (and no redirect)
Add form processing code to your controller:
$form = $this->createForm(ContactForm::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// Do something, e.g. save data
return 'Form submitted successfully';
}
// Display form to user, with validation if submitted and fails validation
return view('template-name', ['form' => $form->createView()]);composer testPlease see CHANGELOG for more information on what has changed recently.
Find out more about how to contribute and our Code of Conduct.
If you discover a security vulnerability within this package, please follow our disclosure procedure.
This package is developed by Studio 24, a human-centered digital agency who build websites and web apps that work for everyone.
The MIT License (MIT). Please see License File for more information.