7

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?

2 Answers 2

3

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" />

:)

2
  • didn't work. i've place the attribute with custom message but all i see is Invalid field: Title when submit.
    – R T
    Commented Mar 30, 2015 at 10:11
  • Agree with prev comment. Doesn't work on Joomla 3.6.5. Is the behaviour dependent on the template used? Commented Sep 15, 2017 at 8:02
1

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;
    }
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.