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:
- A
<script>tag that setswindow.trongateValidationErrorsto a JSON representation of the errors. - 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.jsis part of the Validation module's assets. - JSON is sanitized with
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOTflags 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.trongateValidationErrorsin your own JavaScript.