The Trongate PHP Framework
Documentation
Introduction
Quick Start
Basic Concepts
Understanding Routing
Controllers
Views
Assets
Modules Calling Modules
Parent & Child Modules
Database Operations
Modules within Modules
Templates & Themes
Helpers Explained
Form Handling
Working with Files
The Module Import Wizard
Authorization & Authentication
The API Explorer
Best Practices

Help Improve Our Docs

If you’ve found an error, spotted something missing, or feel a section could be clearer or better explained, we’d love to hear from you. Your feedback helps keep the documentation accurate and useful for everyone.

Please report issues or suggest improvements on GitHub. Community input is invaluable in making the docs stronger.

Not comfortable with GitHub? No problem — you can also get in touch with us directly via our contact form. We welcome all feedback.

The Form Validation Helper

Trongate's validation helper uses server side validation to assist developers in validating submitted form values.

All form validation procedures these following three steps:

  • Submitted form values are passed through some validation test.
  • The results from the validation tests are assigned a boolean value of true (if the submitted form passes validation tests) or false (if there was at least one form validation error).
  • The user is then presented with either a 'success' message or some validation errors, based on the results of the validation tests.
A complete walk-through of how form validation works is available in the 'Form Handling' chapter of these docs.

How To Set Form Validation Rules

Form validation rules can be set by calling upon the validation helper and then invoking Trongate's inbuilt 'set_rules' method. This should be used on a line-by-line basis, whereby each form field that requires validation is processed via a line of code which takes the form:

How To Pipe Multiple Rules Together

Trongate lets you apply multiple validation rules to a submitted value by joining rules together by use of the pipe symbol. For example:

Running Form Validation Tests

The form validation tests that you have created can be applied by calling the validation helper's run() method. Calling run() will produce true if the values passed validation tests and false if there was at least one form validation error.

Displaying Validation Errors

If there are validation errors, they can be displayed by calling Trongate's in-built validation_errors() method from within a view file. For example:

Formatting Validation Errors

By default, each validation error is displayed as a paragraph with red text. However, you can modify the appearance of validation errors by adding opening and closing tags inside your validation_errors() declaration. For example:

Validation Rules Reference

form-validation-table

×