1- # This is my package accessible- forms
1+ # Accessible forms
22
33[ ![ Latest Version on Packagist] ( https://img.shields.io/packagist/v/studio24/accessible-forms.svg?style=flat-square )] ( https://packagist.org/packages/studio24/accessible-forms )
44[ ![ Tests] ( https://img.shields.io/github/actions/workflow/status/studio24/accessible-forms/php.yml?branch=main&label=tests&style=flat-square )] ( https://github.com/studio24/accessible-forms/actions/workflows/php.yml )
55
6- This is where your description should go. Try and limit it to a paragraph or two. Consider adding a small example.
6+ Accessible forms in Laravel and Symfony.
7+
8+ ## Todo
9+
10+ Add any notes here on problems to solve:
11+
12+ - What helpers do we need to make form generation easier?
13+ - Twig in Barryvdh\Form appears to be installed separately to TwigBridge - is this an issue? Twig extension appears to be available for both.
14+ - Can we automate adding the template paths, currently copy config/form.php across
715
816## Requirements
917
@@ -17,9 +25,74 @@ You can install the package via [Composer](https://getcomposer.org/):
1725composer require studio24/accessible-forms
1826```
1927
28+ ### Local install
29+ During testing you can install this from a local copy via:
30+
31+ ``` shell
32+ composer config repositories.local path " ~/Sites/studio24/accessible-forms/"
33+ composer require studio24/accessible-forms:dev-main
34+ ```
35+
36+ To remove this after testing:
37+
38+ ``` shell
39+ ddev composer config repositories.local --unset
40+ ddev composer update
41+ ```
42+
43+ See https://github.com/studio24/dev-playbook/blob/main/composer/testing-local-packages.md
44+
2045## Usage
2146
22- Include some short usage instructions here. If you need more extensive docs save these in docs/ and link to them from here.
47+ ### Laravel
48+
49+ Add the service provider to ` bootstrap/providers.php `
50+
51+ ``` php
52+ return [
53+ Barryvdh\Form\ServiceProvider::class,
54+ ];
55+ ```
56+
57+ To enable TwigExtension in your normal Twig templates (not form twig templates at present) edit ` config/twibridge.php `
58+
59+ ``` php
60+ return [
61+ 'extensions' => [
62+ 'enabled' => [
63+ 'Studio24\AccessibleForms\Twig\AccessibleFormsExtension',
64+ ],
65+ ],
66+ ];
67+ ```
68+
69+ Create a form class:
70+
71+ See https://symfony.com/doc/current/forms.html#creating-form-classes
72+
73+ The form processing workflow is:
74+
75+ 1 . Display form
76+ 2 . Form submitted via POST request
77+ 3 . Form request data is validated
78+ 4 . If pass validation, do something, and redirect to success page
79+ 5 . If fail validation, redisplay form with validation messages (and no redirect)
80+
81+ Add form processing code to your controller:
82+
83+ ``` php
84+ $form = $this->createForm(ContactForm::class);
85+
86+ $form->handleRequest($request);
87+
88+ if ($form->isSubmitted() && $form->isValid()) {
89+ // Do something, e.g. save data
90+ return 'Form submitted successfully';
91+ }
92+
93+ // Display form to user, with validation if submitted and fails validation
94+ return view('template-name', ['form' => $form->createView()]);
95+ ```
2396
2497## Testing
2598
0 commit comments