Trongate Website Homepage

Getting Started with Form Handling

This section provides a hands-on tutorial for implementing Trongate's form handling best practices. We'll use a practical example of managing student records to demonstrate the process.

All of the code that is discussed in this chapter can be downloaded from GitHub:

Get Code From GitHub

Setting Up the Database

Our example application will interact with a database table named 'students'. Here's the SQL code to create this table:

CREATE TABLE students (
  id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
  url_string varchar(255) DEFAULT NULL,
  username varchar(255) DEFAULT NULL,
  first_name varchar(255) DEFAULT NULL,
  last_name varchar(255) DEFAULT NULL,
  email_address varchar(255) DEFAULT NULL
)

Creating the Students Module

In Trongate, it's a best practice to create a module that corresponds to your database table. For our example, we'll create a 'students' module. To get started, follow the following three steps:

  1. Create a new Trongate application within your development environment.
  2. In your modules directory, create a new subdirectory named as 'students'.
  3. Inside the students directory, create two subdirectories: 'controllers' and 'views'.

Directory Structure

After creating the Students module, your modules directory structure should be:

modules/
├── ...
└── students/
    ├── controllers/
    └── views/

This structure organizes your code in a clean, logical manner:

Key Points Regarding Module Structure

This modular structure is a key feature of Trongate, allowing for easy management and scalability of your application.

Next Steps

With this foundation in place, we're ready to dive into the details of form handling with Trongate. On the next page, we'll examine the process of presenting forms, breaking down all of the components and explaining how they work together.