Form Configuration
Enable Forms Module
The forms module is enabled in the installed apps:settings/base.py
Wagtail forms provide a quick way to generate data-collection and contact forms without writing custom code. For complex form requirements, consider using Django’s form framework directly.
Form Models
FormField Model
TheFormField model defines individual form fields:
base/models.py
FormPage Model
TheFormPage model creates pages with customizable forms:
base/models.py
Form Features
Dynamic Field Creation
Editors can add form fields through the admin interface using Available field types include:
InlinePanel:- Single line text
- Multi-line text
- Number
- URL
- Checkbox
- Checkboxes (multiple)
- Radio buttons
- Dropdown
- Date
- DateTime
- Hidden field
Admin Interface
The form page admin interface provides:Form Builder
Drag-and-drop interface to add and reorder form fields without coding.
Submissions Panel
View all form submissions directly in the page editor with export capabilities.
Email Configuration
Configure recipient addresses and email subject for notifications.
Content Integration
Combine forms with StreamField content for rich form pages.
Form Field Configuration
Each form field can be configured with:- Label: The field label shown to users
- Help text: Additional guidance for filling out the field
- Required: Whether the field must be filled
- Field type: The type of input (text, email, checkbox, etc.)
- Choices: For dropdown, radio, and checkbox fields
- Default value: Pre-populated value
Example Form Page
Complete Form Page Implementation
Complete Form Page Implementation
Here’s how all the pieces work together:
base/models.py
Handling Form Submissions
Viewing Submissions
Submissions are accessible through:- FormSubmissionsPanel in the page editor
- Forms section in the Wagtail admin sidebar
- Export to CSV for data analysis
Submission Data
Each submission includes:- Submission date and time
- All form field responses
- IP address (if recorded)
- User information (if authenticated)
Email Notifications
When a form is submitted, Wagtail can send an email notification:Make sure your Django email backend is properly configured in settings for email notifications to work.
API Support
Form fields are exposed through the Wagtail API:Best Practices
Spam Protection
Consider adding CAPTCHA or honeypot fields for public forms to prevent spam submissions.
Required Fields
Mark essential fields as required and provide clear help text for better user experience.
Email Testing
Test email notifications in development to ensure proper configuration before going live.
Data Privacy
Consider GDPR compliance for form submissions, especially for contact and personal information forms.
Customization Options
Extend form functionality by:- Overriding the
serve()method for custom form processing - Adding custom validation logic
- Implementing custom success/error handling
- Storing submissions in external systems
- Adding file upload fields

