You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Installation
Install wagtailcaptcha via pip pip install wagtail-django-recaptcha or add wagtailcaptcha to your Python path.
Add wagtailcaptcha to your INSTALLED_APPS setting.
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
fromwagtail.contrib.forms.modelsimportAbstractFormFieldfromwagtail.admin.panelsimportFieldPanel, InlinePanel, MultiFieldPanelfromwagtail.fieldsimportRichTextFieldfrommodelcluster.fieldsimportParentalKeyfromwagtailcaptcha.modelsimportWagtailCaptchaEmailFormclassSubmitFormField(AbstractFormField):
page=ParentalKey('SubmitFormPage', related_name='form_fields')
classSubmitFormPage(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.')
classMeta:
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.
fromwagtailcaptcha.formsimportWagtailCaptchaFormBuilderfromwagtailcaptcha.modelsimportWagtailCaptchaFormclassCustomFormBuilder(WagtailCaptchaFormBuilder):
# Some custom behaviour...classFormPage(WagtailCaptchaForm):
form_builder=CustomFormBuilder# The rest of the page definition as usual...