This document describes the form handling system in the Hotelaro codebase. It covers the mechanisms for AJAX form submission, CSRF protection, client-side validation, and notification systems (using toastr/Toastify). The focus is on the reusable scripts and patterns that enable secure, user-friendly, and consistent form interactions across the application.
For information about file uploads and asset management, see File Management. For details on utility functions and shared helpers, see Common Helpers.
The form handling system provides:
This system is used throughout both the admin backend and public-facing website for login, registration, booking, configuration, and other interactive forms.
Diagram: "Form Handling System Overview"
AJAX form submission is handled by JavaScript/jQuery scripts that intercept the form's submit event, prevent the default browser behavior, and send the form data to the server using $.ajax.
File: app/Views/common_script/formsubmit.php
File: inc/themes/backend/Admin/Views/submitit.php
Key Features:
| File Path | Usage Context | Key Elements Handled |
|---|---|---|
| app/Views/common_script/formsubmit.php | General forms | CSRF, toastr, redirects |
| inc/themes/backend/Admin/Views/submitit.php | Admin backend forms | toastr, redirects |
All AJAX form submissions include CSRF tokens to prevent cross-site request forgery. The token is:
Relevant Code:
User feedback is provided via notification popups using a custom wrapper around Toastify.js, exposed as a toastr object with methods for different message types.
File: inc/themes/backend/Admin/Views/toster.php
Key Features:
| Method | Description |
|---|---|
| toastr.success(msg) | Show success notification |
| toastr.error(msg) | Show error notification |
| toastr.warning(msg) | Show warning notification |
| toastr.info(msg) | Show info notification |
The form handling scripts update the UI based on the server response:
Relevant Code:
Diagram: "Form Handling Code Entity Map"
Diagram: "AJAX Form Submission Lifecycle"
"toastr (toster.php)"
"Server (Controller)"
"Browser JS (formsubmit.php)"
"User"
"toastr (toster.php)"
"Server (Controller)"
"Browser JS (formsubmit.php)"
"User"
"Submit form"
"POST form data + CSRF"
"JSON {status, message, new_csrf_token, locationChange}"
"Show notification"
"Update button, redirect if needed"
| Entity / Symbol | Description | File(s) |
|---|---|---|
| formsubmit.php | General AJAX form handler | app/Views/common_script/formsubmit.php |
| submitit.php | Admin-specific AJAX form handler | inc/themes/backend/Admin/Views/submitit.php |
| toster.php | Toastr/Toastify notification system | inc/themes/backend/Admin/Views/toster.php |
| csrf_hash(), csrf_token() | CSRF token generation (server-side) | app/Views/common_script/formsubmit.php |