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;
}'
);
?>