When validating a custom field, and the test fails, Joomla returns the following default error message:
**Warning** Invalid field: My Field
How can I specify the message that is returned to explain why it is invalid?
Add the message
attribute, but better like this:
<field name="my_code" type="text" size="15" label="My Code"
validate="myrule" message="Field may only contain A-z or 0-9" />
:)
For an message that may vary, add the message
attribute like this:
public function test(SimpleXMLElement $element, $value, $group = null, JRegistry $input = null, JForm $form = null)
{
if(!preg_match('/^[a-z0-9]+$/i', $value)) {
$element->addAttribute('message', 'Field may only contain A-z or 0-9');
return false;
}elseif(!$somethingelse) {
$element->addAttribute('message', 'Something else is wrong');
return false;
}
ctype_alnum()
function. if (!ctype_alnum($value)) {
php.net/manual/en/function.ctype-alnum.php
Commented
Nov 30, 2018 at 1:05