get_js_injection()

public function get_js_injection(): string

Description

Returns JavaScript code that injects validation errors into the page for client‑side highlighting. Includes two parts:

  1. A <script> tag that sets window.trongateValidationErrors to a JSON representation of the errors.
  2. A <script src="..."> tag that loads the framework's built‑in error‑highlighting JavaScript.

This method enables automatic field highlighting without additional developer JavaScript.

Parameters

This method accepts no parameters.

Return Value

Type Description
string HTML script tags (or empty string if no validation errors exist).

Example Usage

Notes

  • Returns an empty string if $_SESSION['form_submission_errors'] is not set.
  • The JavaScript file highlight_validation_errors.js is part of the Validation module's assets.
  • JSON is sanitized with JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT flags for safe embedding.
  • The highlighting script automatically finds fields with errors and adds CSS classes (typically validation-error).
  • For custom highlighting, you can read window.trongateValidationErrors in your own JavaScript.