This guide discusses the process of building a contact form with the help of the Database Manager and Form Builder.
To follow the steps in this tutorial, you must understand how to use Liquid, YAML, and GraphQL. In addition, you must learn how to interact with Modules on Insites.
We will cover all aspects of forms and retrieving data through the following steps:
You can build a database table using one of two ways:
Building a database table using the Instance Admin is the easiest and fastest way to create your database table. The Insites Admin employs an intuitive user interface that lists available input options and catches errors. Visit the following topics to learn more:
To define a new Table via code, use YAML files in the
app/schema/contact.yml
The basic configuration of a Record consists of a name and a list of Database Fields. In the example above, you have defined three attributes of type
For more information on Database Fields, please visit the Database Fields documentation.
You can build a form using one of two ways:
You may use the Insites Instance Admin user interface to build forms for your database. The forms can then be included on your preferred page for users to be able to input data into your database. Read the following resources for more details:
Now that you have the definition of a
app/forms/contact_form.liquid
The above definition allows name, email, and description attributes and defines validation for each attribute.
This step is automatically done if you use the Insites Instance Admin to create your Database Tables and Forms. Insites configures the forms to interface with your databases, potentially saving you hours of work. However, to demonstrate how things work 'under the hood,' the manual way of fetching data from the databases is discussed.
Now that you have created the
To check if the above query works properly, you can head to the next section to learn how to embed query results with page view.
To render database items within a page, create a page that will respond to given paths:
The page slug for the above URL map will be
app/views/pages/contacts.liquid
app/views/partials/contacts/list.liquid
app/views/partials/contacts/show.liquid
You can display an HTML form on your page using one of two ways:
Insites eliminates the need to construct HTML forms from the ground up. Nevertheless, the following section provides a comprehensive guide on constructing a form from code to offer insight into the underlying technical processes.
To display a form on your site using the Insites Instance Admin:
In Step 2: Define Contact Form-Data Creation, you have created a form file called
The
Please visit our documentation regarding Forms for more information on advanced form configuration.
To display the form on the previously created
app/views/pages/contacts.liquid
As a result, you should be able to create database item objects, called Contacts, with a simple form submission and list them after fetching them with GraphQL.
Deleting a contact using the Instance Admin is straightforward. You may use the documentation on Database Items or CRM for more details. To demonstrate deleting a contact via code, however, and removing a record from the database, create a form called
Then, display a delete button on the list of contacts and include the form as follows:
Much like deleting a contact, Editing a contact is a straightforward process using the Instance Admin. Depending on your website's configuration, you may edit a contact on the Database Manager or CRM. Please visit the Database Items or CRM documentation for more details. To edit a contact via code, you can reuse the form for creating contacts to update a database item. To prefill the form with the correct data, add
app/views/pages/contacts/edit.liquid
You can use the Instance Admin to add email notifications to your form. Visit the Form Builder Notifications and Callbacks documentation for more details. To create email notifications from scratch, create an Email Notification file that will define email configuration and message template. The file should be in the
app/emails/contact_notification.liquid
All request parameters are now accessible in the
At this point, you should restrict access to your created forms and views. Please visit the documentation on Associating an Authorisation Policy with a Form to learn more.
Congratulations! You have learned how to build forms with Records. You can now explore our reference documentation for database fields and tables: Database Fields and Tables.
Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.