Form builder is a collection of tools built on top of Page Builder that help with the creation of HTML forms.
To enable Form Builder, add
Form builder depends on the following packages:
You can install them manually, or you can install them using the django-widgy package:
$ pip install django-widgy[page_builder,form_builder]
When a user submits a
Form will loop through all of
the success handler widgets to do the things that you would normally put in the
form_valid method of a
example. Form Builder provides a couple of built-in success handlers that do
things like saving the data, sending emails, or submitting to Salesforce.
This widget corresponds to the HTML
<form>tag. It acts as a container and also can be used to construct a Django Form class.
Returns a Django Form class based on the FormField widgets inside the form.
Corresponds with the HTML
<label>tag. This is the text that will go inside the label.
Indicates whether or not this field is required. Defaults to True.
A TextField for outputting help text.
This is a widget for all simple
<input>types. It supports the following input types:
date. Respectively they correspond with the following Django formfields:
For custom Widgy owners, Form Builder needs to have a view to use for handling form submissions.
- Each widgy owner should implement a
get_form_action_url(form, widgy_context)method that returns a URL that points to a view (see step 2).
- Create a view to handle form submissions for each owner. Form Builder provides the
class-based views mixin,
HandleFormMixin, to make this easier.
An abstract view mixin for handling form_builder.Form submissions. It inherits from
It should be registered with a URL similar to the following.
HandleFormMixindoes not implement a GET method, so your subclass should handle that. Here is an example of a fully functioning implementation:
from django.views.generic import DetailView from widgy.contrib.form_builder.views import HandleFormMixin class EventDetailView(HandleFormMixin, DetailView): model = Event def post(self, *args, **kwargs): self.object = self.get_object() return super(EventDetailView, self).post(*args, **kwargs)
widgy.contrib.widgy_mezzanine.views.HandleFormViewprovides an even more robust example implementation.