Commit 0e509a3e authored by Falko Timme's avatar Falko Timme

- 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".
parent 0a8f0e4e
......@@ -799,7 +799,9 @@ class tform {
}
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 @@ class tform {
$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 @@ class tform {
$this->errorMessage .= $errmsg."<br />\r\n";
}
}
}
}
}
break;
case 'NOTEMPTY':
if(empty($field_value)) {
......
......@@ -118,6 +118,10 @@ $form["tabs"]['address'] = array (
'customer_no' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'validators' => array ( 0 => array ( 'type' => 'UNIQUE',
'errmsg'=> 'customer_no_error_unique',
'allowempty' => 'y'),
),
'default' => '',
'value' => '',
'separator' => '',
......
......@@ -118,6 +118,10 @@ $form["tabs"]['address'] = array (
'customer_no' => array (
'datatype' => 'VARCHAR',
'formtype' => 'TEXT',
'validators' => array ( 0 => array ( 'type' => 'UNIQUE',
'errmsg'=> 'customer_no_error_unique',
'allowempty' => 'y'),
),
'default' => '',
'value' => '',
'separator' => '',
......
......@@ -135,5 +135,6 @@ $wb['generate_password_txt'] = "Passwort erzeugen";
$wb['repeat_password_txt'] = "Passwort wiederholen";
$wb['password_mismatch_txt'] = "Die Passwörter stimmen nicht überein.";
$wb['password_match_txt'] = "Die Passwörter stimmen überein.";
$wb["customer_no_error_unique"] = 'Die Kundennummer muß einzigartig sein (oder leer).';
?>
......@@ -128,5 +128,6 @@ $wb['generate_password_txt'] = "Passwort erzeugen";
$wb['repeat_password_txt'] = "Passwort wiederholen";
$wb['password_mismatch_txt'] = "Die Passwörter stimmen nicht überein.";
$wb['password_match_txt'] = "Die Passwörter stimmen überein.";
$wb["customer_no_error_unique"] = 'Die Kundennummer muß einzigartig sein (oder leer).';
?>
......@@ -139,4 +139,5 @@ $wb['repeat_password_txt'] = 'Repeat Password';
$wb['password_mismatch_txt'] = 'The passwords do not match.';
$wb['password_match_txt'] = 'The passwords do match.';
$wb['email_error_isemail'] = 'Please enter a valid email address.';
$wb["customer_no_error_unique"] = 'The customer no. must be unique (or empty).';
?>
......@@ -131,4 +131,5 @@ $wb['repeat_password_txt'] = 'Repeat Password';
$wb['password_mismatch_txt'] = 'The passwords do not match.';
$wb['password_match_txt'] = 'The passwords do match.';
$wb['email_error_isemail'] = 'Please enter a valid email address.';
$wb["customer_no_error_unique"] = 'The customer no. must be unique (or empty).';
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment