Skip to main content

A simple recaptcha field for Wagtail Form Pages.

Project description

Wagtail ReCaptcha

PyPI PyPI downloads Build Status codecov License: MIT

Wagtail forms with a ReCaptcha form field/widget integration app. Wagtail ReCaptcha provides an easy way to integrate the django-recaptcha field when using the Wagtail formbuilder.

Check out Awesome Wagtail for more awesome packages and resources from the Wagtail community.

Compatibility

  • Django 5.2, 6.0
  • Wagtail 7.0 LTS, 7.3
  • Python 3.10, 3.11, 3.12, 3.13, 3.14

Installation

  1. Install wagtailcaptcha via pip pip install wagtail-django-recaptcha or add wagtailcaptcha to your Python path.
  2. Add wagtailcaptcha to your INSTALLED_APPS setting.
  3. Configure django-recaptcha as explained in the django recaptcha documentation.

Usage

Field

The quickest way to add a captcha field to a Wagtail Form Page is to inherit from the two options provided, WagtailCaptchaForm or WagtailCaptchaEmailForm. The first options inherits from AbstractForm while the seconds does it from AbstractEmailForm. Either way your page is going to display a captcha field at the end of the form.

Example

from wagtail.contrib.forms.models import AbstractFormField
from wagtail.admin.panels import FieldPanel, InlinePanel, MultiFieldPanel
from wagtail.fields import RichTextField

from modelcluster.fields import ParentalKey

from wagtailcaptcha.models import WagtailCaptchaEmailForm


class SubmitFormField(AbstractFormField):
    page = ParentalKey('SubmitFormPage', related_name='form_fields')


class SubmitFormPage(WagtailCaptchaEmailForm):
    body = RichTextField(blank=True, help_text='Edit the content you want to see before the form.')
    thank_you_text = RichTextField(blank=True, help_text='Set the message users will see after submitting the form.')

    class Meta:
        verbose_name = "Form submission page"


SubmitFormPage.content_panels = [
    FieldPanel('title', classname="full title"),
    FieldPanel('body', classname="full"),
    FieldPanel('thank_you_text', classname="full"),
    InlinePanel('form_fields', label="Form fields"),
    MultiFieldPanel([
        FieldPanel('to_address'),
        FieldPanel('from_address'),
        FieldPanel('subject'),
    ], "Email notification")
]

The captcha field can't be added from the admin UI but will appear in your frontend as the last of the form fields.

If you need to customise the behaviour of the form builder, make sure to inherit from wagtailcaptcha.forms.WagtailCaptchaFormBuilder instead of Wagtail's default form builder, then declare it as usual on the page model.

from wagtailcaptcha.forms import WagtailCaptchaFormBuilder
from wagtailcaptcha.models import WagtailCaptchaForm


class CustomFormBuilder(WagtailCaptchaFormBuilder):
    # Some custom behaviour...


class FormPage(WagtailCaptchaForm):
    form_builder = CustomFormBuilder
    # The rest of the page definition as usual...

For a more thorough example, Made with Wagtail (github.com/springload/madewithwagtail) is an example of an open-source site using this module.

Development

Installation

Requirements: virtualenv, pyenv, twine

git clone git@github.com:wagtail-nest/wagtail-django-recaptcha.git
cd wagtail-django-recaptcha/
virtualenv .venv
source ./.venv/bin/activate

Commands

Use make help to get a list of commands.

Releases

  • Make a new branch for the release of the new version.
  • Update the CHANGELOG.
  • Update the version number in wagtailcaptcha/__init__.py, following semver.
  • Make a PR and squash merge it.
  • Back on master with the PR merged, use make publish (confirm, and enter your password).
  • Finally, go to GitHub and create a release and a tag for the new version.
  • Done!

Acknowledgements

Wagtail ReCaptcha was originally created by Springload. They kindly transferred the project to the Wagtail Nest community in December 2024.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wagtail_django_recaptcha-2.2.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wagtail_django_recaptcha-2.2.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file wagtail_django_recaptcha-2.2.0.tar.gz.

File metadata

  • Download URL: wagtail_django_recaptcha-2.2.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for wagtail_django_recaptcha-2.2.0.tar.gz
Algorithm Hash digest
SHA256 d7340ba346f365f475595b733c4f4ef380bd2e331261d5a5604b57baa3a7b786
MD5 b99ba3548329485d6c3bf9804b2b7889
BLAKE2b-256 aebaca504c45123f07314a0cd83a03c5b3872c3e851e703f0a6ea92fbf6f2e10

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_django_recaptcha-2.2.0.tar.gz:

Publisher: publish.yml on wagtail-nest/wagtail-django-recaptcha

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file wagtail_django_recaptcha-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for wagtail_django_recaptcha-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 094a59cbfd9f02d41e9fd0a294fc3e754e5b5fc5da01cc15a8e08007f3ad2f67
MD5 e5cb5f0f66da851948544d34f90f13b8
BLAKE2b-256 856e51b0f5be85c42364b325ef623cbd7fbc038c10bc3d11fb75b6acfe09cc35

See more details on using hashes here.

Provenance

The following attestation bundles were made for wagtail_django_recaptcha-2.2.0-py3-none-any.whl:

Publisher: publish.yml on wagtail-nest/wagtail-django-recaptcha

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page