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?

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

:)

| improve this answer | |
  • didn't work. i've place the attribute with custom message but all i see is Invalid field: Title when submit. – R T Mar 30 '15 at 10:11
  • Agree with prev comment. Doesn't work on Joomla 3.6.5. Is the behaviour dependent on the template used? – coder.in.me Sep 15 '17 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;
    }
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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