Fields[$FieldName]['Type'] = strtolower($FieldType); $this->Fields[$FieldName]['Required'] = $Required; $this->Fields[$FieldName]['ErrorMessage'] = $ErrorMessage; if (!empty($Options['maxlength'])) { $this->Fields[$FieldName]['MaxLength'] = $Options['maxlength']; } if (!empty($Options['minlength'])) { $this->Fields[$FieldName]['MinLength'] = $Options['minlength']; } if (!empty($Options['comparefield'])) { $this->Fields[$FieldName]['CompareField'] = $Options['comparefield']; } if (!empty($Options['allowperiod'])) { $this->Fields[$FieldName]['AllowPeriod'] = $Options['allowperiod']; } if (!empty($Options['allowcomma'])) { $this->Fields[$FieldName]['AllowComma'] = $Options['allowcomma']; } if (!empty($Options['inarray'])) { $this->Fields[$FieldName]['InArray'] = $Options['inarray']; } if (!empty($Options['regex'])) { $this->Fields[$FieldName]['Regex'] = $Options['regex']; } } function ValidateForm($ValidateArray) { reset($this->Fields); foreach ($this->Fields as $FieldKey => $Field) { $ValidateVar = $ValidateArray[$FieldKey]; if ($ValidateVar != '' || !empty($Field['Required']) || $Field['Type'] == 'date') { if ($Field['Type'] == 'string') { if (isset($Field['MaxLength'])) { $MaxLength = $Field['MaxLength']; } else { $MaxLength = 255; } if (isset($Field['MinLength'])) { $MinLength = $Field['MinLength']; } else { $MinLength = 1; } if (strlen($ValidateVar) > $MaxLength) { return $Field['ErrorMessage']; } elseif (strlen($ValidateVar) < $MinLength) { return $Field['ErrorMessage']; } } elseif ($Field['Type'] == 'number') { if (isset($Field['MaxLength'])) { $MaxLength = $Field['MaxLength']; } else { $MaxLength = ''; } if (isset($Field['MinLength'])) { $MinLength = $Field['MinLength']; } else { $MinLength = 0; } $Match = '0-9'; if (isset($Field['AllowPeriod'])) { $Match .= '.'; } if (isset($Field['AllowComma'])) { $Match .= ','; } if (preg_match('/[^'.$Match.']/', $ValidateVar) || strlen($ValidateVar) < 1) { return $Field['ErrorMessage']; } elseif ($MaxLength != '' && $ValidateVar > $MaxLength) { return $Field['ErrorMessage'].'!!'; } elseif ($ValidateVar < $MinLength) { return $Field['ErrorMessage']."$MinLength"; } } elseif ($Field['Type'] == 'email') { if (isset($Field['MaxLength'])) { $MaxLength = $Field['MaxLength']; } else { $MaxLength = 255; } if (isset($Field['MinLength'])) { $MinLength = $Field['MinLength']; } else { $MinLength = 6; } if (!preg_match("/^".EMAIL_REGEX."$/i", $ValidateVar)) { return $Field['ErrorMessage']; } elseif (strlen($ValidateVar) > $MaxLength) { return $Field['ErrorMessage']; } elseif (strlen($ValidateVar) < $MinLength) { return $Field['ErrorMessage']; } } elseif ($Field['Type'] == 'link') { if (isset($Field['MaxLength'])) { $MaxLength = $Field['MaxLength']; } else { $MaxLength = 255; } if (isset($Field['MinLength'])) { $MinLength = $Field['MinLength']; } else { $MinLength = 10; } if (!preg_match('/^'.URL_REGEX.'$/i', $ValidateVar)) { return $Field['ErrorMessage']; } elseif (strlen($ValidateVar) > $MaxLength) { return $Field['ErrorMessage']; } elseif (strlen($ValidateVar) < $MinLength) { return $Field['ErrorMessage']; } } elseif ($Field['Type'] == 'username') { if (isset($Field['MaxLength'])) { $MaxLength = $Field['MaxLength']; } else { $MaxLength = 20; } if (isset($Field['MinLength'])) { $MinLength = $Field['MinLength']; } else { $MinLength = 1; } if (!preg_match('/^'.USERNAME_REGEX.'$/i', $ValidateVar)) { return $Field['ErrorMessage']; } elseif (strlen($ValidateVar) > $MaxLength) { return $Field['ErrorMessage']; } elseif (strlen($ValidateVar) < $MinLength) { return $Field['ErrorMessage']; } } elseif ($Field['Type'] == 'checkbox') { if (!isset($ValidateArray[$FieldKey])) { return $Field['ErrorMessage']; } } elseif ($Field['Type'] == 'compare') { if ($ValidateArray[$Field['CompareField']] != $ValidateVar) { return $Field['ErrorMessage']; } } elseif ($Field['Type'] == 'inarray') { if (array_search($ValidateVar, $Field['InArray']) === false) { return $Field['ErrorMessage']; } } elseif ($Field['Type'] == 'regex') { if (!preg_match($Field['Regex'], $ValidateVar)) { return $Field['ErrorMessage']; } } } } // while } // function function GenerateJS($FormID) { $ReturnJS = "\r\n"; return $ReturnJS; } } ?>