Skip to main content

Form Designer

Project description

https://github.com/feincms/form-designer/actions/workflows/tests.yml/badge.svg

This form designer does not try to offer every last configuration possibility of Django’s forms, just through the administration interface instead of directly in Python code. Instead, it strives to be a tool which everyone can use right away, without the need for long explanations.

It offers a small set of predefined input fields such as:

  • Text fields (One line and multi line widgets possible)

  • E-mail address fields

  • Checkboxes

  • Dropdowns

  • Radio Buttons

  • Multiple selection checkboxes

  • Hidden input fields

Every field can optionally be declared mandatory, default values and help texts are available too. That’s it.

The default actions (which can be enabled individually) are to send the form data to a list of freely definable email addresses and to store the data in the database so that it can be exported later. An XLSX export of saved submissions is provided too. It is possible to add your own actions as well.

Aside: If you need more options you may want to check out feincms3-forms as well.

Installing the form designer

Install the package using pip:

$ pip install form-designer

Setting up the form designer

  • Add "form_designer" and "admin_ordering" to INSTALLED_APPS.

  • Run ./manage.py migrate form_designer

  • Go into Django’s admin panel and add one or more forms with the fields you require. Also select at least one action in the configuration options selectbox, most often you’d want to select both the “E-mail” and the “Save form submission” option and fill in one ore more email addresses.

If you’re using the form designer with FeinCMS, the content type can be imported from form_designer.contents.FormContent. Otherwise, your code should use the following methods (the code would probably reside in a view):

# Somehow fetch the form_designer.models.Form instance:
instance = get_object_or_404()

# Build the form class:
form_class = instance.form_class()

# Standard form processing:
if request.method == "POST":
    form = form_class(request.POST)

    if form.is_valid():
        # Do what you want, or run the configured processors:
        result = instance.process(form, request)

        # Maybe there's something useful in here:
        pprint(result)

        return HttpResponseRedirect("thanks/")
else:
    form = form_class()

return render(request, "form.html", {"form": form})

Adding custom actions

Custom actions can be added by appending them to Form.CONFIG_OPTIONS:

from form_designer.models import Form

def do_thing(model_instance, form_instance, request, config, **kwargs):
    pass

def do_validate(form_instance, data):
    pass

Form.CONFIG_OPTIONS.append(
    (
        "do_thing",
        {
            "title": _("Do a thing"),
            "form_fields": lambda form: [
                ("optional_form_field", forms.CharField(
                    label=_("Optional form field"),
                    required=False,
                    # validators...
                    # help_text...
                )),
            ],
            "process": do_thing,
            "validate": do_validate,
        },
    )
)

The interesting part is the do_thing callable. It currently receives four arguments, however you should also accept **kwargs to support additional arguments added in the future:

  • model_instance: The Form model instance

  • form_instance: The dynamically generated form instance

  • request: The current HTTP request

  • config: The config options (keys and values defined through form_fields; for example the email action defines an email char field, and accesses its value using config["email"]).

ReCaptcha

To enable ReCaptcha install django-recaptcha and add django_recaptcha to your INSTALLED_APPS. This will automatically add a ReCaptcha field to the form designer. For everything else read through the django-recaptcha readme.

Simple Captcha

To enable django-simple-captcha install django-simple-captcha and add captcha to your INSTALLED_APPS as described in the documentation for django-simple-captcha. This will automatically add a “Simple Captcha” field to the form designer field types.

Override field types

Define FORM_DESIGNER_FIELD_TYPES in your settings file like:

FORM_DESIGNER_FIELD_TYPES = "your_project.form_designer_config.FIELD_TYPES"

In your_project.form_designer_config.py something like:

from django import forms
from django.utils.translation import gettext_lazy as _

FIELD_TYPES = [
    {"type": "text", "verbose_name": _("text"), "field": forms.CharField},
    {"type": "email", "verbose_name": _("email address"), "field": forms.EmailField},
]

Visit these sites for more information

Project details


Download files

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

Source Distribution

form_designer-0.27.3.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

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

form_designer-0.27.3-py3-none-any.whl (37.5 kB view details)

Uploaded Python 3

File details

Details for the file form_designer-0.27.3.tar.gz.

File metadata

  • Download URL: form_designer-0.27.3.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for form_designer-0.27.3.tar.gz
Algorithm Hash digest
SHA256 b206bc6354824cf45c521d0db7a3cf5bbaf66d0fad6431bdd5c684db049f498d
MD5 b3430501735e3b69c02b5bb67c897ecb
BLAKE2b-256 d8a9ec277dadaba6e56b3ea285c829178889d7327cc229b4fa3eabea58d93260

See more details on using hashes here.

File details

Details for the file form_designer-0.27.3-py3-none-any.whl.

File metadata

  • Download URL: form_designer-0.27.3-py3-none-any.whl
  • Upload date:
  • Size: 37.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for form_designer-0.27.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fba2502305c08af4b2ccec29c0867055a02073b73e07f08471f2d3ca57836f83
MD5 770a963a66d8188b59bb1584665f8178
BLAKE2b-256 03193125d79a122e5c19661f94ca396dc452e50175a6252d1afb3efe164a4ea3

See more details on using hashes here.

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