wagtail-honeypot


Namewagtail-honeypot JSON
Version 1.2.0 PyPI version JSON
download
home_pageNone
SummaryAdd optional honeypot protection to your Wagtail forms.
upload_time2024-07-13 10:59:40
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
license MIT License Copyright (c) 2022, Nick Moreton Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords wagtail honeypot forms spam
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Wagtail Honeypot

![Alt text](docs/sample.jpg?raw=true "Title")

## Add optional form spam protection to your Wagtail forms

It should help to reduce form spam by tricking bots into submitting data in fields that should remain empty.

### How it works

When the Wagtail Form is submitted and the honeypot protection is enabled, the honeypot fields & values are available in the `POST` data.

It provides validation for a hidden text field that should remain empty and checks a time interval between the form being displayed and submitted.

If the form is submitted with content in the hidden field or before the interval expires the submission is ignored.

- No email is sent
- No submission is stored

## Installation and setup

Add the package to your python environment.

```bash
pip install wagtail-honeypot
```

Add the package to your settings

```python
INSTALLED_APPS = [
    ...
    "wagtail_honeypot",
    ...
]
```

### The HoneypotFormMixin & HoneypotFormSubmissionMixin

They will add a [honeypot enable/disable](./wagtail_honeypot/models.py#L13) field to your form page model and [custom form submission](./wagtail_honeypot/models.py#L24) method.

If you follow the official Wagtail docs for the [Form Builder](https://docs.wagtail.org/en/stable/reference/contrib/forms/index.html) your form should look something like this...

```python
from wagtail_honeypot.models import (
    HoneypotFormMixin, HoneypotFormSubmissionMixin
)

class FormField(AbstractFormField):
    page = ParentalKey("FormPage", related_name="form_fields")

class FormPage(HoneypotFormMixin, HoneypotFormSubmissionMixin):
    intro = RichTextField(blank=True)
    thank_you_text = RichTextField(blank=True)

    content_panels = AbstractEmailForm.content_panels + [
        FieldPanel("intro", classname="full"),
        InlinePanel("form_fields", label="Form fields"),
        FieldPanel("thank_you_text", classname="full"),
        MultiFieldPanel(
            [
                FieldRowPanel(
                    [
                        FieldPanel("from_address", classname="col6"),
                        FieldPanel("to_address", classname="col6"),
                    ]
                ),
                FieldPanel("subject"),
            ],
            "Email",
        ),
    ]

    honeypot_panels = [
        MultiFieldPanel(
            [FieldPanel("honeypot")],
            heading="Reduce Form Spam",
        )
    ]

    edit_handler = TabbedInterface(
        [
            ObjectList(content_panels, heading="Content"),
            ObjectList(honeypot_panels, heading="Honeypot"),
            ObjectList(Page.promote_panels, heading="Promote"),
            ObjectList(Page.settings_panels, heading="Settings", classname="settings"),
        ]
    )
```

If you prefer you could add the honeypot field to the content_panels rather than a new Tab

```python
# replace
edit_handler = TabbedInterface(
        [
            ObjectList(content_panels, heading="Content"),
            ObjectList(honeypot_panels, heading="Honeypot"),
            ObjectList(Page.promote_panels, heading="Promote"),
            ObjectList(Page.settings_panels, heading="Settings", classname="settings"),
        ]
    )

# with
content_panels = content_panels + honeypot_panels
```

*Run `python manage.py makemigrations` and `python manage.py migrate` here*

### Honeypot Template Tag

Add the following template tag loader to your form page.

```html
{% load honeypot_tags %}
```

Add the Honeypot fields template tag anywhere inside the form

```html
<form>
...
{% honeypot_fields page.honeypot %}
...
</form>
```

In your Wagtail site you should now be able to add a new form page, *enable the honeypot field*.

Test that the honey pot field works

1. View the newly created form page.  
2. The honeypot field is visible and could be submitted with any value.  
3. Test it out by submitting the form with the honeypot field set to any value. It won't save the form submission or send an email if you have enabled that in your form page.

## Hide the Honeypot field

The honeypot field should be invisible to when viewed in a browser.

### Use CSS & JS to hide the honeypot field

The package has some basic css and javascript you can use to hide the field.

Example: add the following to your form template.

```html
<!-- recommended:
to add both but you can use one or the other -->

{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/honeypot.css' %}">
{% endblock extra_css %}

<!-- alternative:
but without the css above loaded first
the field could be seen for a flash while the page loads -->

{% block extra_js %}
<script src="{% static 'js/honeypot.js' %}"></script>
{% endblock extra_js %}
```

The field should be visibly hidden and not be available to receive any value from a site visitor.

> When rendered, the fields will have the HTML attributes `tabindex="-1" autocomplete="off"` to prevent a site visitor from using the tab key to move to the field and disable any autocomplete browser functions.

## Developer Documentation

[Developer Docs](docs/developer.md) for detailed help.

## Versions

Wagtail honey pot can be used in environments:

- Python 3.9+
- Django 4.2+
- Wagtail 5.1+

## Contributions

Contributions or ideas to improve this package are welcome.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "wagtail-honeypot",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "wagtail, honeypot, forms, spam",
    "author": null,
    "author_email": "Nick Moreton <nickmoreton@me.com>",
    "download_url": "https://files.pythonhosted.org/packages/51/ef/a80d992444174da89a2e66156d199e57900a5ed742fe6bca61395790ef30/wagtail_honeypot-1.2.0.tar.gz",
    "platform": null,
    "description": "# Wagtail Honeypot\n\n![Alt text](docs/sample.jpg?raw=true \"Title\")\n\n## Add optional form spam protection to your Wagtail forms\n\nIt should help to reduce form spam by tricking bots into submitting data in fields that should remain empty.\n\n### How it works\n\nWhen the Wagtail Form is submitted and the honeypot protection is enabled, the honeypot fields & values are available in the `POST` data.\n\nIt provides validation for a hidden text field that should remain empty and checks a time interval between the form being displayed and submitted.\n\nIf the form is submitted with content in the hidden field or before the interval expires the submission is ignored.\n\n- No email is sent\n- No submission is stored\n\n## Installation and setup\n\nAdd the package to your python environment.\n\n```bash\npip install wagtail-honeypot\n```\n\nAdd the package to your settings\n\n```python\nINSTALLED_APPS = [\n    ...\n    \"wagtail_honeypot\",\n    ...\n]\n```\n\n### The HoneypotFormMixin & HoneypotFormSubmissionMixin\n\nThey will add a [honeypot enable/disable](./wagtail_honeypot/models.py#L13) field to your form page model and [custom form submission](./wagtail_honeypot/models.py#L24) method.\n\nIf you follow the official Wagtail docs for the [Form Builder](https://docs.wagtail.org/en/stable/reference/contrib/forms/index.html) your form should look something like this...\n\n```python\nfrom wagtail_honeypot.models import (\n    HoneypotFormMixin, HoneypotFormSubmissionMixin\n)\n\nclass FormField(AbstractFormField):\n    page = ParentalKey(\"FormPage\", related_name=\"form_fields\")\n\nclass FormPage(HoneypotFormMixin, HoneypotFormSubmissionMixin):\n    intro = RichTextField(blank=True)\n    thank_you_text = RichTextField(blank=True)\n\n    content_panels = AbstractEmailForm.content_panels + [\n        FieldPanel(\"intro\", classname=\"full\"),\n        InlinePanel(\"form_fields\", label=\"Form fields\"),\n        FieldPanel(\"thank_you_text\", classname=\"full\"),\n        MultiFieldPanel(\n            [\n                FieldRowPanel(\n                    [\n                        FieldPanel(\"from_address\", classname=\"col6\"),\n                        FieldPanel(\"to_address\", classname=\"col6\"),\n                    ]\n                ),\n                FieldPanel(\"subject\"),\n            ],\n            \"Email\",\n        ),\n    ]\n\n    honeypot_panels = [\n        MultiFieldPanel(\n            [FieldPanel(\"honeypot\")],\n            heading=\"Reduce Form Spam\",\n        )\n    ]\n\n    edit_handler = TabbedInterface(\n        [\n            ObjectList(content_panels, heading=\"Content\"),\n            ObjectList(honeypot_panels, heading=\"Honeypot\"),\n            ObjectList(Page.promote_panels, heading=\"Promote\"),\n            ObjectList(Page.settings_panels, heading=\"Settings\", classname=\"settings\"),\n        ]\n    )\n```\n\nIf you prefer you could add the honeypot field to the content_panels rather than a new Tab\n\n```python\n# replace\nedit_handler = TabbedInterface(\n        [\n            ObjectList(content_panels, heading=\"Content\"),\n            ObjectList(honeypot_panels, heading=\"Honeypot\"),\n            ObjectList(Page.promote_panels, heading=\"Promote\"),\n            ObjectList(Page.settings_panels, heading=\"Settings\", classname=\"settings\"),\n        ]\n    )\n\n# with\ncontent_panels = content_panels + honeypot_panels\n```\n\n*Run `python manage.py makemigrations` and `python manage.py migrate` here*\n\n### Honeypot Template Tag\n\nAdd the following template tag loader to your form page.\n\n```html\n{% load honeypot_tags %}\n```\n\nAdd the Honeypot fields template tag anywhere inside the form\n\n```html\n<form>\n...\n{% honeypot_fields page.honeypot %}\n...\n</form>\n```\n\nIn your Wagtail site you should now be able to add a new form page, *enable the honeypot field*.\n\nTest that the honey pot field works\n\n1. View the newly created form page.  \n2. The honeypot field is visible and could be submitted with any value.  \n3. Test it out by submitting the form with the honeypot field set to any value. It won't save the form submission or send an email if you have enabled that in your form page.\n\n## Hide the Honeypot field\n\nThe honeypot field should be invisible to when viewed in a browser.\n\n### Use CSS & JS to hide the honeypot field\n\nThe package has some basic css and javascript you can use to hide the field.\n\nExample: add the following to your form template.\n\n```html\n<!-- recommended:\nto add both but you can use one or the other -->\n\n{% block extra_css %}\n<link rel=\"stylesheet\" href=\"{% static 'css/honeypot.css' %}\">\n{% endblock extra_css %}\n\n<!-- alternative:\nbut without the css above loaded first\nthe field could be seen for a flash while the page loads -->\n\n{% block extra_js %}\n<script src=\"{% static 'js/honeypot.js' %}\"></script>\n{% endblock extra_js %}\n```\n\nThe field should be visibly hidden and not be available to receive any value from a site visitor.\n\n> When rendered, the fields will have the HTML attributes `tabindex=\"-1\" autocomplete=\"off\"` to prevent a site visitor from using the tab key to move to the field and disable any autocomplete browser functions.\n\n## Developer Documentation\n\n[Developer Docs](docs/developer.md) for detailed help.\n\n## Versions\n\nWagtail honey pot can be used in environments:\n\n- Python 3.9+\n- Django 4.2+\n- Wagtail 5.1+\n\n## Contributions\n\nContributions or ideas to improve this package are welcome.\n",
    "bugtrack_url": null,
    "license": " MIT License  Copyright (c) 2022, Nick Moreton  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.  ",
    "summary": "Add optional honeypot protection to your Wagtail forms.",
    "version": "1.2.0",
    "project_urls": {
        "Changelog": "https://github.com/wagtail-packages/wagtail-honeypot/blob/release/CHANGELOG",
        "Issues": "https://github.com/wagtail-packages/wagtail-honeypot/issues",
        "Repository": "https://github.com/wagtail-packages/wagtail-honeypot"
    },
    "split_keywords": [
        "wagtail",
        " honeypot",
        " forms",
        " spam"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a4ba305a6ddc6741877dfc337b6df61fbdbb2ca0acaa9a7d28381769db6b9a6",
                "md5": "b64921cb8b50b45d4324a3a6896dcba2",
                "sha256": "19683ec6f62d1a9ff1086bf387dcab35679f95efc31a1bb7bebb3490861337d2"
            },
            "downloads": -1,
            "filename": "wagtail_honeypot-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b64921cb8b50b45d4324a3a6896dcba2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7916,
            "upload_time": "2024-07-13T10:59:38",
            "upload_time_iso_8601": "2024-07-13T10:59:38.602691Z",
            "url": "https://files.pythonhosted.org/packages/3a/4b/a305a6ddc6741877dfc337b6df61fbdbb2ca0acaa9a7d28381769db6b9a6/wagtail_honeypot-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "51efa80d992444174da89a2e66156d199e57900a5ed742fe6bca61395790ef30",
                "md5": "57d15b2e364d41c63104622c7e48ebeb",
                "sha256": "9d5fb3af8c2803bc1e6ce8651d474c65bbc7048ab8d3db3c858b9adedc6ec064"
            },
            "downloads": -1,
            "filename": "wagtail_honeypot-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "57d15b2e364d41c63104622c7e48ebeb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 10714,
            "upload_time": "2024-07-13T10:59:40",
            "upload_time_iso_8601": "2024-07-13T10:59:40.187793Z",
            "url": "https://files.pythonhosted.org/packages/51/ef/a80d992444174da89a2e66156d199e57900a5ed742fe6bca61395790ef30/wagtail_honeypot-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-13 10:59:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wagtail-packages",
    "github_project": "wagtail-honeypot",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "wagtail-honeypot"
}
        
Elapsed time: 0.70822s