Intro
This tutorial is about
How to create a form in PIPEFORCE.
This tutorial is relevant for
Low-Code Developers who want to learn how to create and display web forms as a fundamental part of an application to accomplish several critical objectives like: Data collection, data review and data validation.
The final form will look similar to this:
Prerequisites
You need to have a developer account in a PIPEFORCE customer or trial instance.
PIPEFORCE instance should have version 9.5 or higher.
If you don’t have an account yet, just request it here: https://pipeforce.io/jetzt-testen/.
It is recommended to go through the Tutorial 01: Basic Concepts before, to get a better understanding of the PIPEFORCE basics.
Step 1: Create Form Schema
In this step you will create a Form Schema (= define the fields of a form)
Noteworthy
A Form Schema is a JSON Schema
A Form Schema defines all the fields and their data types of a form.
In order to create such a Form Schema, follow these instructions
Login to portal with a valid developer account.
Navigate to LOW CODE → Properties.
Click the plus + icon at the top.
Select App and create a new app with name:
io.pipeforce.tutorial-03-forms
.Select this app and click again the plus + icon.
Now select Form Schema and create it inside this app with name: person.
The new schema was created and pre-filled with an example person schema.
Later, you can edit this form schema and remove, change or add data fields to your form.
For this tutorial, do not change anything and leave it as it is.
At this step you have created a Form Schema which defines the fields and their data types of the form.
For more information go to the public docs: Form Schema.
Step 2: Create Form Config
In this step we gonna create the Form Config and define the layout and configs parameters of a form
Noteworthy about the Form Config
It contains all form configuration settings like where the input data of the form comes from and needs to be written to (output).
It optionally defines layout customizations.
It optionally contains advanced validation rules.
It optionally contains advanced event handlers for advanced form logics.
The Form Config is a JSON file.
In order to create a simple Form Config, follow now these steps:
Go to LOW CODE -> Properties.
Select your app
io.pipeforce.tutorial-03-forms
in the tree.Click the plus + icon.
Select Form Config.
Create a new Form Config with name: person
In the property tree, select your app and click on the plus icon + to create a new property inside.
Give a name to the Form Config then click Create.
A new Form Config was created for you with a pre-configured title and configuration.
Leave this Form Config as it is for now.
10. Since we did not specify any layout information here, the default layout will be used: All fields defined in the Form Schema will be displayed in vertical format.
This is how the Form Config JSON will look like:
{ "id": "person", "title": "person", "public": false, "description": "", "schema": "$uri:property:global/app/io.pipeforce.tutorial-03-forms/schema/person", "output": "$uri:property:global/app/io.pipeforce.tutorial-03-forms/data/person/" }
id = The unique id of this form. Can be any string.
title = The title to display on this form.
description = The description to display for this form.
public = Whether this form should be reachable without login.
schema = The path to the Form Schema to be used for this form. The prefix
$uri:property:
defines that the schema can be found in the property store.output = The path to the location where to write the data of the submitted form as JSON. The prefix
$uri:property:
defines that the result will be written to the property store at this location.
For more details go to the public docs: Form Config.
At this step you have created a Form Config which defines the configuration and optionally layout customization, validation rules and script references.
Step 3: Execute the Form
After the Form Schema and the Form Config have been created, you can open your form.
To do so follow these steps:
Navigate to APPS -> Installed Apps.
Click on the app io.pipeforce.tutorial-03-forms.
Click on person.
Now you should see the form with the example fields like this:
Submit the form
Add valid values in any of the fields.
Click on SUBMIT.
Noteworthy
After you clicked on SUBMIT, the form data will be validated and then send to the server as JSON. This JSON will then be stored to your app's data folder: io.pipeforce.tutorial-03-forms/data/...
Any new submit will create a new entry in the data folder with a random uuid.
The reason why this works this way is because in the Form Config, the output path was configured to this location, like this:
"output": "$uri:property:global/app/io.pipeforce.tutorial-03-forms/data/person/"
Note: Since this path ends with a /
, a new entry is created with a random uuid every time you write to this URI location.
In the next step of this tutorial, you will learn how to handle such a form submit in the backend in order to execute some additional action after the user has submitted a form.
Step 4: Handle the Form Submit
In this step you will learn how to handle a Form Submit at server side and add logic to be executed after submit.
Noteworthy
After a submit, the form data will be send as JSON to the server.
By default this JSON is stored in the property store as configured by the output parameter in the Form Config and the event property.created will be fired.
Optionally, you can listen to the property.created event and trigger the execution of a pipeline.
But this is optional. By default, form data is stored in property store so it doesn't get lost and you can process them at any time later.
Follow these steps in order to trigger a pipeline after the form was submitted:
This pipeline should then send an email.
Go to AUTOMATION -> Properties.
Select your app io.pipeforce.tutorial-03-forms.
Click the plus + icon.
Click Pipeline and create a new pipeline
Give the pipeline a name and then click Create.
Copy and paste this YAML script to the pipeline editor and overwrite any existing content:
pipeline: - event.listen: eventKey: property.created filter: ${body.target.path.contains('global/app/io.pipeforce.tutorial-03-forms/data/')} - mail.send: to: name@email.tld subject: "Form was submitted" message: | The form was submitted: ${body.target}
As you can see, this pipeline listens to the property.created event. Since the form submit writes to the location global/app/io.pipeforce.tutorial-03-forms/data/
(as configured by the output parameter) you can listen to this write event and execute your business logics. Which is sending a simple email in this example.
Change the email address
name@email.tld
to your own address.Save the pipeline. After save, the pipeline will be automatically registered as a listener to the property.created event.
Execute the form again.
10. You should now receive a new email on any form submit.
In this step you have learned how to execute logic at server side after a form has been submitted.
Step 5: Customize Form Layout
In this step you will learn how to change the default form layout
Noteworthy
By default if nothing is specified, the default layout will be used which lists all fields vertically, one after another.
You can change this default layout in the Form Config.
"Layouting" means changing the orientation, placement and styling of the form and its fields.
Follow these instructions in order to change the default layout of your form:
Go to AUTOMATION -> Properties.
Open the Form Config
form/person
inside your app io.pipeforce.tutorial-03-forms.Replace the content of the Form Config by the JSON listed below, and then click SAVE
{ "id": "person", "title": "Add person", "public": false, "description": "", "schema": "$uri:property:global/app/io.pipeforce.tutorial-03-forms/schema/person", "output": "$uri:property:global/app/io.pipeforce.tutorial-03-forms/data/person/", "layout":{ "orientation":"vertical", "items":[ { "orientation":"horizontal", "title": "Name", "border": true, "items":[ { "field":"firstName" }, { "field":"lastName" }] }, { "field":"age" }, { "field":"gender" }, { "field":"birthDate" } ] } }
As you can see in the Form Config, the layout part was added which defines a different orientation of the fields.
Navigate to APPS -> Installed Apps and click your app io.pipeforce.tutorial-03-forms.
Now you should see that the “person” tile has changed to “Add person”. Click it.
Here you can see the changed layout: first Name and last Name fields are now in the same line (horizontal) and all other fields are in separate line (vertical):
For more information about layout options, go to Form Config & Layout.
Add Comment