The Validation Module
The Validation Module delivers robust and secure form validation with support for standard field types, file uploads, and custom validation rules. Features include CSRF protection, multiple date/time format validators, file type and size validation, image dimension checking, and comprehensive error handling. The module makes it easy to validate user input with intuitive rule definitions and automatic error message generation.
Comprehensive guidance for this module can be found in the Form Handling chapter of the Trongate PHP framework documentation.
__construct()
Constructor for the Validation module. Initializes the module and stores a reference to the calling controller for callback methods.
display_errors()
Displays validation errors in one of three formats: general HTML list, inline field‑specific errors, or JSON API response. This method is the object‑oriented counterpart to the validation_errors() helper function.
get_js_injection()
Returns JavaScript code that injects validation errors into the page for client‑side highlighting. Includes two parts:
reset_language()
Resets the validation language to the system default. Removes any sticky language preference from the session and cookie.
run()
Executes form validation and returns the result. This method performs automatic CSRF protection, runs validation tests, and stores errors in session for display.
set_caller()
Sets the calling controller instance, enabling callback validation rules. Callback rules allow you to define custom validation logic in your controller methods.
set_language()
Sets the language for validation error messages. Changes both the session/cookie language (via the Language module) and loads the corresponding validation language file.
set_rules()
Defines validation rules for a specific form field or file upload. This method is the foundation of Trongate's validation system, allowing you to specify which fields are required, what format they should have, and what constraints they must meet. Each call to set_rules() validates one field according to the specified rules.