Hi everyone,
I created the validation of a field as described like this:
-
in custom/Extension/modules/“Module”/.php
I added$dictionary["Module"]["fields"]["field"]["validation"] = array ( 'type' => 'callback', 'callback' => " function(formname,nameIndex) { var str1; str1=$('#' + nameIndex).val(); name='&name='+$('#' + nameIndex).val(); var return_value='true'; if (str1.length == 0) { add_error_style(formname,nameIndex,'ERROR. Empty field!!!'); return false; } else { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { if (xmlhttp.status == 200){ var response = xmlhttp.responseText.trim(); if(response=='found'){ add_error_style(formname,nameIndex,'ERROR. name already present!'); return_value='false'; } } } }; xmlhttp.open('GET', 'index.php?entryPoint=entryPointName' + name + id_yard, false); xmlhttp.send(); if(return_value=='false'){ return false; } } }" );
-
I created an entrypoint (entryPointName)
-
the entrypoint refers to a file (getHint.php)
in this file there is the query (in SQL) to check the existence of the name I’m going to insert.
Everything works perfectly, at least for the insertion of new records, but if I open a record already created to make changes, trying to save it, the check is performed on the field of this record and tells me that the name is already present.
How can I solve this problem? Any ideas? Thanks