Form Builder
You can of course create forms with regular HTML if you want, but for your information, Stratox comes with a highly dynamic form builder that helps you create dynamic, responsive, and engaging web forms with ease. Out of the box, there is a form template view that will help you get started, which you can change to suit your needs.
Setting Up the Form
Begin by opening the controller file src/controllers/PagesController.js
. Then, import the form view (src/templates/views/Form.js
) at the top of the document:
Note: The Form.js
view comes pre-installed, so you do not need to create it yourself.
Then add a contact
method to the PagesController
. We will first add the form view and then add form fields to it:
This time, I encourage you to connect the contact
method in the controller to the router (router.get('/contact', [PagesController, "contact"])
) and add it to the navigation yourself. Once you're done, visit your browser to see the results.
Adding the Submit Page
Next, let's add the form submit page to the controller and router.
Controller
First, create a new method called contactPost
inside the PagesController
.
This view will display the form fields once the form has been submitted.
Router
Next, connect contactPost
in PagesController
to a route as follows:
Note: We're using "post" instead of "get" because the form uses post
, and the router needs to handle post
requests to catch it. If you have different methods, you can add duplicate URI paths without any risk of collision.
You can add this just below your created route, which hopefully looks like this: router.get('/contact', [PagesController, "contact"])
.
Visit your browser, and click the submit button on the contact page to see the results.
Available Form Fields
Available form fields out of the box:
text (password, tel, email, number, etc.)
textarea
date
datetime
hidden
select
radio
checkbox
submit (button)
group
views/components
These fields can be combined with all views and components that you have created!
Form Field Settings
Available form field settings/configs out of the box. See working examples below:
Adding Template Blocks in Form
To pass template layout blocks to a form using Stratox, follow these steps:
Import the view at the top of the document/PageController:
Note: The Ingress component does not exists by default, it is just an example. You will need to use a view component that you have created!
Utilize the Stratox function
partial
to set the view at your specified position in the form:
Last updated