Custom validation error messages

Is there an established method for displaying a custom error message when validating a field? I have stumbled across the built-in “add_error_style()” function, and this works fine except that as well as my customised error message, I also see below it (whether or not there is a value in the input field) the standard “Missing required field” message - I assume this is triggered by my returning “false” from the validation callback function. Is there a way of suppressing this spurious message? My code is as below :



<?php
  $dictionary['SA_Referrals']['fields']['name']['validation'] = array(
    'type' => 'callback',
    'callback' => 'function(formname,nameIndex) {

      var duplicateKey = 0;

      var name = document.forms[formname][nameIndex].value;
      var id   = document.forms[formname]["record"].value;

      $.ajax({
        url : "index.php",
        type : "get",
        data : {
          "entryPoint" : "Referrals_checkDupName",
          "id"         : id,
          "name"       : name
        },
        async : false,
        success : function(returnData) {
          if (returnData && (returnData > 0)) {
            duplicateKey = 1;
          }
        }
      });

      if (duplicateKey) {
        add_error_style(formname,nameIndex,"Referral number already exists");
        return false;
      }

      return true;
    }'
  );
?>

Hello, tomglare!
Have you solved this problem?

We have the same behavior in 7.7.4. But in 7.10.x validation is working fine.
Which files do I need to change in 7.7.4?

Thanx in advance to anyone, who’d like to share experience :slight_smile:

That’s what i mean. See attached images