whoami
Lucas Jenß
cat /etc/motd
The Coding Journal ツ — Notes taken on an epic coding journey. Technical solutions, debugging notes, and practical guides from the trenches of software development.
ls -la ~/languages/
- drwxr-xr-x
- ▶ PHP
- ▶ Ruby
- ▶ Scala
- ▶ C#
- ▶ JavaScript
- ▶ Objective-C
- ▶ Shell Scripting
ls -la ~/toolchain/
- drwxr-xr-x
- ▶ Typo3
- ▶ Akka
- ▶ Capistrano
- ▶ Git
- ▶ MAMP
- ▶ Adobe Illustrator
- ▶ NSTrackingArea (Cocoa)
uname -a
- drwxr-xr-x
- ▶ Mac OS X
- ▶ Unix
Adding a custom JavaScript validator to TYPO3 backend forms
TYPO3 backend forms often need a rule that built-in required and email checks cannot express: an Australian postcode format, a project reference, a conditional field, or a limit tied to another record. A custom JavaScript validator gives editors immediate feedback while they work, instead of waiting for a save request to return an error.
The important distinction is that browser validation assists the editor; it does not decide whether a record may be stored. FormEngine usually renders ordinary TCA fields, while a custom backend module can contain a completely separate form. Each surface has different extension points, and the validation code must not assume that every TYPO3 screen behaves like FormEngine.
Implementation details also shift between TYPO3 versions. A team in Sydney or Melbourne may support a mixed estate, so a solution should work with Chrome or Edge on Windows as well as Safari on macOS. Copying a snippet between TYPO3 v12, v13 and an older installation without checking the relevant FormEngine API is an avoidable source of regressions.
The pattern below uses a small rule contract, a delegated listener, native accessibility attributes and a server-side counterpart. Australian teams also need to account for day-first dates, UTC timestamps across daylight-saving changes, and the Australian Privacy Principles when a form captures personal information. If the Privacy Act 1988 applies to the organisation, its controls should shape what the validator logs and displays.
Finding the right validation boundary
Start by identifying the form surface and the exact field that needs the rule. For a TCA-backed FormEngine screen, config.eval remains the right place for standard checks such as required, trim or email; a project-specific rule should sit beside those checks rather than replace them. A Form Framework form needs its own element and validator configuration, while a custom module can use the events around its own template.
The rule must have a stable identifier. A custom FormEngine field control or render type can emit a marker such as data-validator-rule="postcode", allowing the JavaScript module to find the input without relying on a generated element ID. That marker also survives the partial DOM replacements made while FormEngine refreshes a record.
Whatever the rendering route, define the server-side counterpart before shipping the browser code. A DataHandler validation path or domain service can reject the same invalid value for direct form saves, API writes, imports and scheduled jobs. Comparing implementation notes from other maintainers can help separate core behaviour from extension behaviour; Abhay Chauhan’s TYPO3 notes provide a useful external reference before you create a custom control.
Designing a small, testable rule
Keep browser rules independent of TYPO3 DOM objects. A useful contract accepts the raw string and returns a valid flag plus an editor-facing message. The rule can then be unit tested and reused in the PHP validator without relying on a browser environment.
const validators = {
postcode(value) {
const candidate = value.trim();
if (candidate === '') {
return { valid: true, message: '' };
}
return /^\d{4}$/.test(candidate)
? { valid: true, message: '' }
: {
valid: false,
message: 'Enter a four-digit Australian postcode.'
};
}
};
Define empty-value behaviour deliberately. If the field is optional, an empty value passes the custom rule while the normal required evaluation remains responsible for mandatory fields. The four-digit check is appropriate for Australian postcodes, but an international form may need a configurable country rule instead of a hard-coded local assumption.
Turn the result into accessible feedback. Store the message in a nearby element, connect it with aria-describedby, set aria-invalid to true only for a failing field, and use setCustomValidity() so browser tooling receives the same text. Do not rely on colour alone, and never replace the field’s label with an error message.
Test the pure rule against empty strings, surrounding spaces, malformed values and valid edge cases. Then test the rendered field with a keyboard and a screen reader. If the rule transforms a value, make that transformation explicit on both sides; silently trimming or reformatting in JavaScript can leave the submitted value different from what the editor believes they entered.
Connecting JavaScript to FormEngine
Load the module through TYPO3’s backend JavaScript registration instead of placing a script tag in a template. A v12-style registration in the extension bootstrap looks like this:
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\JavaScriptModuleLoader;
$loader = GeneralUtility::makeInstance(JavaScriptModuleLoader::class);
$loader->addJavaScriptModule(
'my_extension/backend-validator',
'EXT:my_extension/Resources/Public/JavaScript/backend-validator.js'
);
Method names and module packaging differ in v13, so check the loader API provided by the version you support. Scope the asset to backend requests, and keep the module free of frontend-only dependencies. This prevents the validator from increasing the public page weight or interfering with Form Framework assets in the frontend.
Use delegated focusout and input listeners rather than binding to fields during page load. FormEngine can replace a field after an AJAX operation, and a delegated listener continues to work when the element changes.
document.addEventListener('focusout', (event) => {
const field = event.target.closest('[data-validator-rule]');
if (field) {
applyValidation(field);
}
});
document.addEventListener('input', (event) => {
const field = event.target.closest('[data-validator-rule]');
if (field?.getAttribute('aria-invalid') === 'true') {
applyValidation(field);
}
});
Call the same validation function from the save action. Native constraint validation does not necessarily stop FormEngine’s AJAX save cycle, so an invalid field needs an explicit guard, a visible message and focus moved to the first error. Keep the save hook in the extension, not in a global click handler, because editors can also save through keyboard shortcuts or the module menu.
Testing across versions and daily workflows
Test the complete edit cycle, not only page load. Save the record, reopen it, trigger FormEngine’s AJAX refresh, use a conditional field and verify that the error disappears after correction. Repeat the workflow in Chrome, Edge and Safari, including keyboard-only use and browser zoom. This catches event timing and styling issues that a unit test cannot see.
Local toolchains deserve the same scrutiny. On macOS, a generic compiler error may reflect the installed binary rather than the project code; my notes on solving NDK build issues illustrate why checking exact versions is useful. Apply that habit to FormEngine assets: clear caches, rebuild static assets in the supported way and compare the generated DOM before blaming the validator.
Avoid logging entered values. A rule failure can be recorded with the field name, validator identifier and editor identifier, while the personal value stays out of logs where possible. That habit supports the Australian Privacy Principles and reduces the amount of personal information copied into monitoring systems. Render local dates as DD/MM/YYYY values when required, but store and compare timestamps in a timezone-independent format.
Choose each enforcement layer for the job it can actually perform:
| Approach | Best use | Feedback | Authoritative? |
|---|---|---|---|
Built-in eval |
Required fields, trimming, email and standard formats | Native and server-side checks | Yes for supported rules |
| Custom JavaScript validator | Project-specific guidance and browser-only cross-field checks | Immediate feedback in the editor | No |
| Server-side rule or domain validator | Business rules and data-integrity requirements | Error during saving or API processing | Yes |
A dependable validation and rollout checklist
A custom validator becomes maintainable when its responsibilities are narrow. The browser module should identify the field, run a named rule and present feedback; PHP code should decide whether the value is acceptable for storage. This separation makes each layer easier to test and prevents a polished error message from being mistaken for a security control.
Before putting the rule into a production form, check the following:
- Attach the rule only to named fields, with explicit optional-field behaviour.
- Keep the rule function pure and cover empty, whitespace and malformed inputs.
- Repeat validation in PHP and test form saves, APIs and imports where applicable.
- Verify
aria-invalid,aria-describedby, keyboard focus and visible error styling. - Log rule identifiers rather than submitted personal values.
Start with one low-risk field, exercise the full save and reload cycle in each supported browser, then expand the rule set once both browser and PHP checks agree. That rollout gives editors a faster feedback loop without weakening TYPO3’s server-side guarantees.
cat ~/interests.json
| Key | Value |
|---|---|
| editor | Terminal-first workflow |
| os | Mac OS X / Unix |
| vcs | Git, distributed version control |
| deploy | Capistrano, cron automation |
| graphics | SVG, Adobe Illustrator troubleshooting |
| networking | IP validation, SSH, VPN |
git log --oneline --reverse
Solving SVG import issues in Adobe Illustrator CS6 and CC
When importing an SVG into Illustrator, the operation fails with an unknown error [CANT]. A workaround for this Adobe-side bug.
Solving NDK build issues on OS X
Troubleshooting native development kit compilation problems on Mac OS X.
Programmatically adding PHP generated TypoScript to the backend configuration
Integrating dynamically generated TypoScript into Typo3 backend setups using PHP.
ArgumentError: Could not parse PKey: no start line
Debugging an SSH key parsing error encountered during deployment.
Validating IP-Addresses in PHP
Using PHP filter functions with flags like FILTER_FLAG_IPV4 and FILTER_FLAG_IPV6, and understanding how filter_var handles reserved IP addresses.
Cocoa: Using NSTrackingArea
A short tutorial on using Cocoa's NSTrackingArea to capture mouseEntered and mouseExited events.
cat ~/contact.txt