Create Form to Write to a Database TableLast Updated: 07/15/2016 Introduced in Verision: 2.0 |
This article will show you how to create a form that writes to a database table.
In this tutorial we will create a flow that lets us create new entries in a TV show database table.
You’ll need to start with a designer project: http://decdocs3x.wpengine.com/creating-a-designer-project/
Because you want to read from a database or write to a database you’ll need a flow: http://decdocs3x.wpengine.com/creating-your-first-form/?display_cat=108
1. Add a form as a your first step to this flow.
2. Add controls to the form to gather data. We will need the following fields:
- Show Title
- First Year
- Number of Episodes
- Network
- Description
3. Now that we have a form that collects the data we need to get this data to the database.
You can integrate with an existing database table: http://decdocs3x.wpengine.com/integrating-an-external-database-with-a-flow/?display_cat=114
or you can create a new database stored type right in Decisions: http://decdocs3x.wpengine.com/simple-database-structure/?display_cat=131
For this example we will create a simple database type that looks like the screenshot below. Please take note of the “Type Name” setting. You will need this in the next step.
NOTE: It’s very important that “Generate Flow Steps” is checked so that we automatically get a ‘Save’ step for use in the next step.
4. Put your flow back into edit mode by hitting the ‘Edit’ action.
5. Browse to the ‘Integrations’ folder in the toolbox on the right hand side.
6. Under ‘Integrations’ you should see a set of steps named after your ‘Type Name’ from step 3 above.
7. Put the ‘Save’ step in your flow. It will be invalid at first.
8. To get all the data from the form into the Save step you can right click the Save step and choose ‘Show Mapping Editor.’ The mapping editor is NOT the only way to setup the data in the save step, but it is a great way to visualize different data types and map data from one type into another. In this case we will use it to map the form data into the database table structure. When you first open the mapping editor it will look like the screen shot below.
9. On the right hand side you see a variable named ‘value’. This is the new entry that will be written to the database. Where the small orange text says ‘Unknown’ click, and change your option to ‘Build Data’. Now you will see all the properties in your table.
10. Drag lines from the fields on the left to the table structure on the right.
11. Run your process and check the database for your results.