Skip to main content

Add support for customizable forms in Volto

Project description

Latest Version Egg Status https://img.shields.io/pypi/pyversions/collective.volto.formsupport.svg?style=plastic:alt:Supported-PythonVersions License

collective.volto.formsupport

Add some helper routes and functionalities for Volto sites with form blocks provided by volto-form-block Volto plugin.

plone.restapi endpoints

@submit-form

Endpoint that the frontend should call as a submit action.

You can call it with a POST on the context where the block form is stored like this:

> curl -i -X POST http://localhost:8080/Plone/my-form/@submit-form -H 'Accept: application/json' -H 'Content-Type: application/json' --data-raw '{"block_id": "123456789", "data": [{"field_id": "foo", "value":"foo", "label": "Foo"},{"field_id": "from", "value": "support@foo.com"}, {"field_id":"name", "value": "John Doe", "label": "Name"}]}'

where:

  • my-form is the context where we have a form block

  • block_id is the id of the block

  • data contains the submitted form data

Calling this endpoint, it will do some actions (based on block settings) and returns a 204 response.

@form-data

This is an expansion component.

There is a rule that returns a form-data item into “components” slot if the user can edit the context (Modify portal content permission) and there is a block that can store data.

Calling with “expand=true”, this endpoint returns the stored data:

> curl -i -X GET http://localhost:8080/Plone/my-form/@form-data -H 'Accept: application/json' -H 'Content-Type: application/json' --user admin:admin

And replies with something similar:

{
    "@id": "http://localhost:8080/Plone/my-form/@form-data",
    "items": [
        {
        "block_id": "123456789",
        "date": "2021-03-10T12:25:24",
        "from": "support@foo.com",
        "id": 912078826,
        "name": "John Doe"
        },
        ...
    ],
    "items_total": 42
}

@form-data-export

Returns a csv file with all data (only for users that have Modify portal content permission):

> curl -i -X GET http://localhost:8080/Plone/my-form/@form-data-export -H 'Accept: application/json' -H 'Content-Type: application/json' --user admin:admin

If form fields changed between some submissions, you will see also columns related to old fields.

@form-data-clear

Reset the store (only for users that have Modify portal content permission):

> curl -i -X GET http://localhost:8080/Plone/my-form/@form-data-clear -H 'Accept: application/json' -H 'Content-Type: application/json' --user admin:admin

Form actions

Using volto-form-block you can set if the form submit should send data to an email address or store it into an internal catalog (or both).

Send

If block is set to send data, an email with form data will be sent to the recipient set in block settings or (if not set) to the site address.

If ther is an attachments field in the POST data, these files will be attached to the emal sent.

Store

If block is set to store data, we store it into the content that has that block (with a souper.plone catalog).

The store is an adapter registered for IFormDataStore interface, so you can override it easily.

Only fields that are also in block settings are stored. Missing ones will be skipped.

Block serializer

There is a custom block serializer for type form.

This serializer removes all fields that start with “**default_**" if the user can’t edit the current context.

This is useful because we don’t want to expose some internals configurations (for example the recipient email address) to external users that should only fill the form.

Examples

This add-on can be seen in action at the following sites:

Translations

This product has been translated into

  • Italian

Installation

Install collective.volto.formsupport by adding it to your buildout:

[buildout]

...

eggs =
    collective.volto.formsupport

and then running bin/buildout

Contribute

License

The project is licensed under the GPLv2.

Authors

This product was developed by RedTurtle Technology team.

RedTurtle Technology Site

Contributors

Changelog

1.0.2 (2021-03-24)

  • Fix form_data for anon. [cekk]

1.0.1 (2021-03-24)

  • Fix README for pypi. [cekk]

1.0.0 (2021-03-24)

  • Initial release. [cekk]

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

collective.volto.formsupport-1.0.2.tar.gz (30.0 kB view details)

Uploaded Source

File details

Details for the file collective.volto.formsupport-1.0.2.tar.gz.

File metadata

  • Download URL: collective.volto.formsupport-1.0.2.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for collective.volto.formsupport-1.0.2.tar.gz
Algorithm Hash digest
SHA256 32a3697bc6264953855e12494633b1941710be0e80a121a9dc59bffda83391fe
MD5 146d83e65733625827659044c6d49abf
BLAKE2b-256 f55237e2298bf453fa4a19c9b524261d0f9d121067073f75ffc1dd0e3a5d2170

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