Your under the impression that a HOOK and a callback is the same thing. Acenes was not correct, in that the “validateFormField” is only used in the FE Form Generator, so that cannot be use in the BE.
The only way is to throw Exception in the save_callback, this is exactly how leo does this in the DC_Table.php driver just above where the save_callback is initiated. He tests for DCA parameters, e.g. if the item is “unique” and then he does a throw Exception(). Maybe you are not using the throw Exeptions with valid parameters. What you can do is to do a print_r($varValue); die(); at that point just to test if it even reaches your validation code.
However, in other hooks, it depends. The addCustomRegexp HOOK is completely different as that is called inside the widget, so you simply call the widget->addError(). Why did you not look at the sample from leo’s website, so you can copy that?
Code:
// config.php
$GLOBALS['TL_HOOKS']['addCustomRegexp'][] = array('MyClass', 'myAddCustomRegexp');
// MyClass.php
public function myAddCustomRegexp($strRegexp, $varValue, Widget $objWidget)
{
if ($strRegexp == 'postal')
{
if (!preg_match('/^0-9{4,6}$/', $varValue))
{
$objWidget->addError('Field ' . $objWidget->label . ' should be a postal code.');
}
return true;
}
return false;
}
Bookmarks