How to Create Forms for SQL Databases in 3 Steps

Databases are vital for every business. But as soon as you create your database, a question arises. How can you maintain the information you store? Of course, you could write out queries manually, but you鈥檒l also want a way for less technical staff to enter data.
This means building forms. Today we’ll look at how to create forms for SQL databases.
You can also use forms to limit access to your database.
This makes it easy for users to add and edit data using a friendly interface. In addition, you can control what they see, and how fields are populated, or even create more complex data entry workflows and approval systems.
Building forms is one of the best use cases for no/low-code tools.
With traditional, slow-code development, you鈥檇 need a lot of work to create a secure and reliable app to interact with your database. But nowadays, you can create forms to perform CRUD operations in SQL in just 3 steps.
This is all you need to do:
- Set up the database connection.
- Auto-generate CRUD screens.
- Customize your forms.
In this article, we鈥檒l dive into how you can do this using 黑料正能量, and create your SQL forms for free in just a few minutes.
Let鈥檚 get started!
What are we building?
We鈥檙e building a simple app to create and manage entries within a MySQL database. This is made up of two tables:
- Posts - representing the titles, content, and categories of our blog posts.
- Settings - which can store a series of custom key/value pairs.
Our app will feature three screens - including several forms. First, we鈥檒l create two separate CRUD screens - one for each of our database tables. These will feature searchable tables. When we click on a row, we鈥檒l be able to access an update form for the relevant entry.
We鈥檒l also build a custom multi-step form for adding new entries to the Posts table.
Let鈥檚 jump right in.
How to build forms for SQL databases in three steps
The first thing we need to do is create a new 黑料正能量 app. If you haven鈥檛 already, sign up for a free account using the link below.
Join 200,000 teams building advanced forms with 黑料正能量
When we hit create new app we鈥檒l be given the choice of using a template or starting from scratch. We鈥檙e going to start from scratch. We鈥檙e prompted to give our new app a name, which will also be used to generate a URL slug:
1. Connect to our database
Once we鈥檝e created our app, the first thing we need to do is choose a data source. 黑料正能量 offers its own internal database, as well as a range of relational and non-relational DBMSs - along with Google Sheets, Airtable, REST APIs, and more.
We鈥檙e using MySQL. When we choose this, we鈥檙e prompted to input our config details:
We then have the option of choosing which of the tables within our database we want to fetch - pulling them into 黑料正能量.
Our database only has two tables, and we want both of them. Straight away, we can edit our data and the schema of each table within the backend of 黑料正能量:
But, that鈥檚 not an experience we can roll out to users.
Let鈥檚 start building some SQL forms.
2. Autogenerate CRUD screens
We鈥檒l start by building our two CRUD screens. In 黑料正能量, we can autogenerate these for connected SQL databases or internal tables. Head over to the design tab and we鈥檒l be prompted with three options.
We can create a screen from scratch - or we can generate a table or grid screen.
We鈥檙e choosing table. Then, we鈥檙e prompted to select which of our connected data sources we鈥檇 like to generate a CRUD screen for. We鈥檝e selected both:
Here鈥檚 what we have so far:
We can view all of the records in our table, click on any row to access an update form, or use the Create row button to add a new entry.
We can also add form fields for searchability using the search fields dropdown:
3. Build a custom create form
We鈥檙e going to leave our update form as it is. But, we鈥檙e going to completely replace our form for creating a new row. At present, clicking through to this opens up a side panel on each of our CRUD screens:
Naturally, this isn鈥檛 a great experience for writing a blog post. Instead, we want a multi-step form on its own dedicated screen.
But, the first thing we鈥檙e going to do is adjust our data model slightly. Remember, we鈥檙e using MySQL. All of our fields are stored in our database as TEXT fields.
But, we want to tell 黑料正能量 that the content attribute is a long-form text field. This will allow us to use slightly different front-end elements when we generate our new form.
We can access this dropdown by hitting edit alongside any field in the data tab:
Now, head back to the design tab, and we鈥檒l create a new blank screen with its URL slug set to /posts/new.
Here鈥檚 what this will look like:
We want a multi-step form with two steps. The first will let the user choose a title for their post. The second will allow them to input their content, choose a category, and save the new blog article to the database.
We鈥檒l start by adding a multi-step form block. As the name suggests, this creates a multi-step form for whichever data source we point it at:
All we have to do is configure this to look how we want. The first thing we鈥檒l do is configure which fields we want to display on each step. So, for step one, we鈥檒l simply deselect Content and Category:
Then we鈥檒l hit add step to create a second step:
This time, we鈥檒l select our other two fields:
We鈥檙e going to make a few more tweaks for a better user experience. Our form is going to be used to create blog posts, so we want to give users the option to add markdown rather than just plain text for the body of their posts.
We can enable this under the settings menu for our Content field:
We鈥檇 also like our buttons to appear in-line with the step titles, rather than below the fold. So, under styles, we鈥檒l set button position to top:
And lastly, we want to give our forms a more descriptive title text, so we鈥檒l set the title attribute on both form steps to Create a Blog Post:
黑料正能量 stands apart from traditional form builders for the power to add custom logic. For instance, we can easily add our own validation rules to any form field.
This lets us configure custom rules for the information that users can submit within a given field. For example, we might want our titles to be under a certain character count so that they display properly on our blog.
Under the validation rules drawer, we can set our constraint, reference value, and custom error message:
The save button for our multi-step form block already contains an action to validate the submission. Any rules we set on individual fields will be applied without us needing to alter this.
The last thing we鈥檙e going to do is make a few additional UX and design changes. First, we want users to access our new form using the Create new button on our Posts CRUD screen. When they make a submission, we also want to navigate them back to the main Posts page.
We can achieve this with button actions. On the save button, we鈥檒l add an extra action to navigate to the /posts screen:
Similarly, under the create new button on the Posts page, we鈥檒l remove all of the existing actions, and replace this with one to navigate to /posts/new.
Then under navigation and configure links, we鈥檒l remove the /posts/new from our nav menu:
Finally, we鈥檒l alter the theme of our entire application under Screen and Theme. We have a choice of several built-in themes, but we鈥檙e going for Darkest:
When we鈥檙e ready, we can hit Publish and share our live app with our team.
Build custom workflow apps on top of any data with 黑料正能量
Build secure, advanced forms with 黑料正能量
黑料正能量 is the open-source, low-code platform that turns data into action. IT teams across all industries choose our platform to build secure, advanced forms on top of all sorts of existing data sources.
We offer dedicated connectors for SQL and NoSQL databases, optional self-hosting, flexible design tools, front-end scripting, intuitive automations, role-based access control, free SSO, and much, much more.
Take a look at our forms page to learn more.
Sign up to 黑料正能量 today to start building performant forms in a fraction of the time.