From 0e509a3e29baf9dcb9f730af58f765becacf8f5f Mon Sep 17 00:00:00 2001 From: ftimme <ft@falkotimme.com> Date: Mon, 22 Oct 2012 10:48:59 -0400 Subject: [PATCH] - Added check for unique customer numbers (empty customer numbers are allowed as well). - Extended UNIQUE validator to allow empty values if "allowempty" option is set to "y". --- interface/lib/classes/tform.inc.php | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/interface/lib/classes/tform.inc.php b/interface/lib/classes/tform.inc.php index 7789a81..66615d0 100644 --- a/interface/lib/classes/tform.inc.php +++ b/interface/lib/classes/tform.inc.php @@ -799,7 +799,9 @@ } break; case 'UNIQUE': - if($this->action == 'NEW') { + if($validator['allowempty'] != 'y') $validator['allowempty'] = 'n'; + if($validator['allowempty'] == 'n' || ($validator['allowempty'] == 'y' && $field_value != '')){ + if($this->action == 'NEW') { $num_rec = $app->db->queryOneRecord("SELECT count(*) as number FROM ".$escape.$this->formDef['db_table'].$escape. " WHERE $field_name = '".$app->db->quote($field_value)."'"); if($num_rec["number"] > 0) { $errmsg = $validator['errmsg']; @@ -809,7 +811,7 @@ $this->errorMessage .= $errmsg."<br />\r\n"; } } - } else { + } else { $num_rec = $app->db->queryOneRecord("SELECT count(*) as number FROM ".$escape.$this->formDef['db_table'].$escape. " WHERE $field_name = '".$app->db->quote($field_value)."' AND ".$this->formDef['db_table_idx']." != ".$this->primary_id); if($num_rec["number"] > 0) { $errmsg = $validator['errmsg']; @@ -819,7 +821,8 @@ $this->errorMessage .= $errmsg."<br />\r\n"; } } - } + } + } break; case 'NOTEMPTY': if(empty($field_value)) { -- Gitblit v1.9.1