Skip to content

Commit

Permalink
Forms documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemonteith committed Jun 14, 2021
1 parent 99ed672 commit 287c979
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/components/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Wagtail site settings must be enabled with the `wagtailnhsukfrontend.settings` a

example: [Header (via settings)](./header.md#wagtail-site-settings)

### Forms

Form rendering needs to be enabled with some config changes. See the [forms documentation](./forms.md)


## List of Components

- [Action Link](./action_link.md)
Expand Down
39 changes: 39 additions & 0 deletions docs/components/forms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Forms

Before implementing any forms, make sure you have read the guidance in the Digital Service Manual [https://service-manual.nhs.uk/content/how-to-write-good-questions-for-forms](https://service-manual.nhs.uk/content/how-to-write-good-questions-for-forms).

## Settings

Add the `wagtailnhsukfrontend.forms` app to `INSTALLED_APPS`.

```py
INSTALLED_APPS = [
...
'wagtailnhsukfrontend.forms',
...
]
```

Add the `FORM_RENDERER` setting to tell django to use the nhsukfrontend form templates.

```py
FORM_RENDERER = 'wagtailnhsukfrontend.forms.renderers.NHSUKFrontendRenderer'
```

## Rendering the form

Form fields can be rendered with the `nhsuk_form` templatetag.
As usual with Django forms, it is your responsibility to render the `<form>` element, submit button and csrf_token as appropriate.

Assuming you have a `form` in your template context which is a `django.forms.Form` instance;
```django
{% load nhsukfrontendforms_tags %}
<form method="POST" novalidate>
{% csrf_token %}
{% nhsuk_form form %}
<input class="nhsuk-button" type="submit" value="Submit" />
</form>
```

0 comments on commit 287c979

Please sign in to comment.