[1] | 1 | <?php |
---|
| 2 | /** |
---|
[42] | 3 | * FormValidator.inc.php |
---|
[1] | 4 | * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information |
---|
| 5 | * |
---|
[136] | 6 | * The FormValidator class provides a method for validating input from |
---|
[1] | 7 | * http requests and displaying errors. |
---|
| 8 | * |
---|
[144] | 9 | * @requires codebase/lib/Validator.inc.php |
---|
[1] | 10 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
[106] | 11 | * @version 1.8 |
---|
[1] | 12 | * |
---|
[136] | 13 | * Example of use: |
---|
| 14 | --------------------------------------------------------------------- |
---|
| 15 | // The object that validates form input. |
---|
| 16 | require_once 'codebase/lib/FormValidator.inc.php'; |
---|
| 17 | $fv = new FormValidator(); |
---|
| 18 | |
---|
[144] | 19 | $fv->empty('field_name', sprintf(_("%s cannot be blank."), _("Field name"))); |
---|
[151] | 20 | $fv->stringLength('field_name', 0, 255, sprintf(_("%s must be %d-to-%d characters in length."), _("Field name"), 0, 255)); |
---|
[136] | 21 | $fv->isInteger('field_name', sprintf(_("%s must be an integer."), _("Field name"))); |
---|
| 22 | $fv->checkRegex('field_name', '/^\d{4}$|^$/', true, sprintf(_("%s must be in MMYY format."), _("Field name"))); |
---|
[151] | 23 | $fv->numericRange('field_name', 0, 65535, sprintf(_("%s must be a number between %d and %d."), _("Field name"), 0, 65535)); |
---|
[136] | 24 | $fv->validatePhone('field_name'); |
---|
| 25 | $fv->validateEmail('field_name'); |
---|
| 26 | $fv->validateStrDate('field_name', sprintf(_("%s must be a valid date in YYYY-MM-DD format."), _("Field name"))); |
---|
| 27 | if (is_null($var)) { |
---|
| 28 | $fv->addError('field_name', sprintf(_("%s is invalid."), _("Field name"))); |
---|
| 29 | } |
---|
| 30 | if ($fv->anyErrors()) { |
---|
| 31 | // Errors! |
---|
| 32 | } |
---|
| 33 | --------------------------------------------------------------------- |
---|
[1] | 34 | */ |
---|
[42] | 35 | |
---|
[144] | 36 | // Credit card types are defined in class Validator. |
---|
| 37 | |
---|
| 38 | require_once 'codebase/lib/Validator.inc.php'; |
---|
| 39 | |
---|
| 40 | class FormValidator extends Validator { |
---|
| 41 | |
---|
[266] | 42 | // Class parameters. |
---|
| 43 | var $_params = array( |
---|
| 44 | 'error' => ' sc-msg-error ', |
---|
| 45 | 'warning' => ' sc-msg-warning ', |
---|
| 46 | 'notice' => ' sc-msg-notice ', |
---|
| 47 | 'success' => ' sc-msg-success ', |
---|
| 48 | ); |
---|
| 49 | |
---|
[100] | 50 | // Array filling with error messages. |
---|
[1] | 51 | var $errors = array(); |
---|
[96] | 52 | |
---|
[1] | 53 | /** |
---|
[266] | 54 | * Set (or overwrite existing) parameters by passing an array of new parameters. |
---|
| 55 | * |
---|
| 56 | * @access public |
---|
| 57 | * @param array $params Array of parameters (key => val pairs). |
---|
| 58 | */ |
---|
| 59 | function setParam($params) |
---|
| 60 | { |
---|
| 61 | $app =& App::getInstance(); |
---|
| 62 | |
---|
| 63 | if (isset($params) && is_array($params)) { |
---|
| 64 | // Merge new parameters with old overriding only those passed. |
---|
| 65 | $this->_params = array_merge($this->_params, $params); |
---|
| 66 | } else { |
---|
| 67 | $app->logMsg(sprintf('Parameters are not an array: %s', $params), LOG_ERR, __FILE__, __LINE__); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /** |
---|
| 72 | * Return the value of a parameter, if it exists. |
---|
| 73 | * |
---|
| 74 | * @access public |
---|
| 75 | * @param string $param Which parameter to return. |
---|
| 76 | * @return mixed Configured parameter value. |
---|
| 77 | */ |
---|
| 78 | function getParam($param) |
---|
| 79 | { |
---|
| 80 | $app =& App::getInstance(); |
---|
| 81 | |
---|
| 82 | if (isset($this->_params[$param])) { |
---|
| 83 | return $this->_params[$param]; |
---|
| 84 | } else { |
---|
| 85 | $app->logMsg(sprintf('Parameter is not set: %s', $param), LOG_DEBUG, __FILE__, __LINE__); |
---|
| 86 | return null; |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | /** |
---|
[1] | 91 | * Return the current list of errors. |
---|
| 92 | * |
---|
| 93 | * @return array an array of errors in the following arrangement: |
---|
| 94 | * keys: the name of the variable with an error |
---|
| 95 | * vals: the message to display for that error |
---|
| 96 | */ |
---|
| 97 | function getErrorList() |
---|
| 98 | { |
---|
| 99 | return $this->errors; |
---|
| 100 | } |
---|
[42] | 101 | |
---|
[1] | 102 | /** |
---|
| 103 | * Add an error to the errors stack. |
---|
| 104 | * |
---|
| 105 | * @param string $form_name The name of the incoming form variable. |
---|
| 106 | * @param string $msg The error message for that form. |
---|
| 107 | * @param int $type The type of message: MSG_NOTICE, |
---|
| 108 | * MSG_SUCCESS, MSG_WARNING, or MSG_ERR. |
---|
| 109 | * @param string $file __FILE__. |
---|
| 110 | * @param string $line __LINE__. |
---|
| 111 | */ |
---|
| 112 | function addError($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null) |
---|
| 113 | { |
---|
| 114 | $this->errors[] = array( |
---|
| 115 | 'name' => $form_name, |
---|
| 116 | 'message' => $msg, |
---|
| 117 | 'type' => $type, |
---|
| 118 | 'file' => $file, |
---|
| 119 | 'line' => $line |
---|
| 120 | ); |
---|
| 121 | } |
---|
[42] | 122 | |
---|
[1] | 123 | /** |
---|
| 124 | * Check whether any errors have been triggered. |
---|
| 125 | * |
---|
| 126 | * @param string $form_name the name of the incoming form variable |
---|
| 127 | * |
---|
[42] | 128 | * @return bool true if any errors were found, or if found for |
---|
[1] | 129 | * a variable of $form_name, false otherwise |
---|
| 130 | */ |
---|
| 131 | function anyErrors($form_name=null) |
---|
| 132 | { |
---|
| 133 | if (isset($form_name)) { |
---|
| 134 | foreach ($this->errors as $err) { |
---|
| 135 | if ($err['name'] == $form_name) { |
---|
[178] | 136 | return $err['type']; |
---|
[1] | 137 | } |
---|
| 138 | } |
---|
| 139 | return false; |
---|
[144] | 140 | } else { |
---|
| 141 | return (sizeof($this->errors) > 0); |
---|
[1] | 142 | } |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | /** |
---|
| 146 | * Reset the error list. |
---|
| 147 | */ |
---|
| 148 | function resetErrorList() |
---|
| 149 | { |
---|
| 150 | $this->errors = array(); |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | /** |
---|
| 154 | * Prints the HTML for displaying error messages. |
---|
| 155 | * |
---|
| 156 | * @access public |
---|
| 157 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
| 158 | * @since 15 Jul 2005 01:39:14 |
---|
| 159 | */ |
---|
| 160 | function printErrorMessages() |
---|
| 161 | { |
---|
[136] | 162 | $app =& App::getInstance(); |
---|
[1] | 163 | if ($this->anyErrors()) { |
---|
[166] | 164 | ?><div class="sc-msg" id="sc-msg-formvalidator"><?php |
---|
[1] | 165 | $errors = $this->getErrorList(); |
---|
[136] | 166 | foreach ($errors as $e) { |
---|
| 167 | if ('' != $e['message'] && is_string($e['message'])) { |
---|
| 168 | if (error_reporting() > 0 && $app->getParam('display_errors') && isset($e['file']) && isset($e['line'])) { |
---|
| 169 | echo "\n<!-- [" . $e['file'] . ' : ' . $e['line'] . '] -->'; |
---|
[1] | 170 | } |
---|
[136] | 171 | switch ($e['type']) { |
---|
[1] | 172 | case MSG_ERR: |
---|
[136] | 173 | echo '<div class="sc-msg-error">' . $e['message'] . '</div>'; |
---|
[1] | 174 | break; |
---|
[42] | 175 | |
---|
[1] | 176 | case MSG_WARNING: |
---|
[136] | 177 | echo '<div class="sc-msg-warning">' . $e['message'] . '</div>'; |
---|
[1] | 178 | break; |
---|
[42] | 179 | |
---|
[1] | 180 | case MSG_SUCCESS: |
---|
[136] | 181 | echo '<div class="sc-msg-success">' . $e['message'] . '</div>'; |
---|
[1] | 182 | break; |
---|
[42] | 183 | |
---|
[1] | 184 | case MSG_NOTICE: |
---|
| 185 | default: |
---|
[136] | 186 | echo '<div class="sc-msg-notice">' . $e['message'] . '</div>'; |
---|
[1] | 187 | break; |
---|
| 188 | } |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | ?></div><?php |
---|
| 192 | } |
---|
| 193 | } |
---|
[42] | 194 | |
---|
[1] | 195 | /** |
---|
| 196 | * If this form has an error, print an error marker like "<<". |
---|
| 197 | * |
---|
| 198 | * @param string $form_name the name of the incoming form variable |
---|
| 199 | * @param string $marker A string to print if there is an error. if |
---|
| 200 | * not provided, use default. |
---|
| 201 | */ |
---|
| 202 | function err($form_name, $marker=null) |
---|
| 203 | { |
---|
[178] | 204 | if (false !== ($type = $this->anyErrors($form_name))) { |
---|
[1] | 205 | if (isset($marker)) { |
---|
| 206 | echo $marker; |
---|
| 207 | } else { |
---|
[178] | 208 | switch ($type) { |
---|
| 209 | case MSG_ERR: |
---|
| 210 | default: |
---|
[266] | 211 | echo $this->getParam('error'); |
---|
[178] | 212 | break; |
---|
| 213 | |
---|
| 214 | case MSG_WARNING: |
---|
[266] | 215 | echo $this->getParam('warning'); |
---|
[178] | 216 | break; |
---|
| 217 | |
---|
[266] | 218 | case MSG_NOTICE: |
---|
| 219 | echo $this->getParam('notice'); |
---|
[178] | 220 | break; |
---|
| 221 | |
---|
[266] | 222 | case MSG_SUCCESS: |
---|
| 223 | echo $this->getParam('success'); |
---|
[178] | 224 | break; |
---|
| 225 | } |
---|
[1] | 226 | } |
---|
| 227 | } |
---|
| 228 | } |
---|
| 229 | |
---|
| 230 | /** |
---|
[144] | 231 | * Ensure the length of string is non-zero. |
---|
[1] | 232 | * |
---|
| 233 | * @param string $form_name the name of the incoming form variable |
---|
| 234 | * @param string $msg the message to display on error |
---|
| 235 | * |
---|
| 236 | * @return bool true if form is not empty, false otherwise. |
---|
| 237 | */ |
---|
| 238 | function notEmpty($form_name, $msg='') |
---|
| 239 | { |
---|
[144] | 240 | if (parent::notEmpty(getFormData($form_name))) { |
---|
[1] | 241 | return true; |
---|
| 242 | } else { |
---|
[144] | 243 | $this->addError($form_name, $msg); |
---|
[1] | 244 | return false; |
---|
| 245 | } |
---|
| 246 | } |
---|
[144] | 247 | |
---|
| 248 | /* |
---|
| 249 | * We were using the isEmpty method *wrong* all these years and should have been using notEmpty. |
---|
| 250 | * But the fact is the only use is to ensure a value is not empty, so this function simply becomes |
---|
| 251 | * an alias of the one-true notEmpty() function. |
---|
| 252 | * @since 03 Jun 2006 22:56:46 |
---|
| 253 | */ |
---|
[1] | 254 | function isEmpty($form_name, $msg='') |
---|
| 255 | { |
---|
[241] | 256 | $this->notEmpty($form_name, $msg); |
---|
[1] | 257 | } |
---|
| 258 | |
---|
| 259 | /** |
---|
| 260 | * Check whether input is a string. |
---|
| 261 | * |
---|
| 262 | * @param string $form_name the name of the incoming form variable |
---|
| 263 | * @param string $msg the message to display on error |
---|
| 264 | * |
---|
| 265 | * @return bool true if form is a string, false otherwise. |
---|
| 266 | */ |
---|
| 267 | function isString($form_name, $msg='') |
---|
| 268 | { |
---|
[144] | 269 | if (parent::isString(getFormData($form_name))) { |
---|
| 270 | return true; |
---|
| 271 | } else { |
---|
[1] | 272 | $this->addError($form_name, $msg); |
---|
| 273 | return false; |
---|
| 274 | } |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | /** |
---|
| 278 | * Check whether input is a number. Allows negative numbers. |
---|
| 279 | * |
---|
| 280 | * @param string $form_name the name of the incoming form variable |
---|
| 281 | * @param string $msg the message to display on error |
---|
| 282 | * |
---|
| 283 | * @return bool true if no errors found, false otherwise |
---|
| 284 | */ |
---|
| 285 | function isNumber($form_name, $msg='') |
---|
| 286 | { |
---|
[144] | 287 | if (parent::isNumber(getFormData($form_name))) { |
---|
| 288 | return true; |
---|
| 289 | } else { |
---|
[1] | 290 | $this->addError($form_name, $msg); |
---|
| 291 | return false; |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | /** |
---|
| 296 | * addError if input is NOT an integer. Don't just use is_int() because the |
---|
| 297 | * data coming from the user is *really* a string. |
---|
| 298 | * |
---|
| 299 | * @param string $form_name the name of the incoming form variable |
---|
| 300 | * @param string $msg the message to display on error |
---|
| 301 | * |
---|
| 302 | * @return bool true if value is an integer |
---|
| 303 | */ |
---|
| 304 | function isInteger($form_name, $msg='', $negative_ok=false) |
---|
| 305 | { |
---|
[144] | 306 | if (parent::isInteger(getFormData($form_name), $negative_ok)) { |
---|
| 307 | return true; |
---|
| 308 | } else { |
---|
[1] | 309 | $this->addError($form_name, $msg); |
---|
| 310 | return false; |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | |
---|
| 314 | /** |
---|
| 315 | * Check whether input is a float. Don't just use is_float() because the |
---|
[42] | 316 | * data coming from the user is *really* a string. Integers will also |
---|
[1] | 317 | * pass this test. |
---|
| 318 | * |
---|
| 319 | * @param string $form_name the name of the incoming form variable |
---|
| 320 | * @param string $msg the message to display on error |
---|
| 321 | * |
---|
| 322 | * @return bool true if value is a float |
---|
| 323 | */ |
---|
| 324 | function isFloat($form_name, $msg='', $negative_ok=false) |
---|
| 325 | { |
---|
[144] | 326 | if (parent::isFloat(getFormData($form_name), $negative_ok)) { |
---|
| 327 | return true; |
---|
| 328 | } else { |
---|
[1] | 329 | $this->addError($form_name, $msg); |
---|
| 330 | return false; |
---|
| 331 | } |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | /** |
---|
| 335 | * Check whether input is an array. |
---|
| 336 | * |
---|
| 337 | * @param string $form_name the name of the incoming form variable |
---|
| 338 | * @param string $msg the message to display on error |
---|
| 339 | * |
---|
| 340 | * @return bool true if value is a float |
---|
| 341 | */ |
---|
| 342 | function isArray($form_name, $msg='') |
---|
| 343 | { |
---|
[144] | 344 | if (parent::isArray(getFormData($form_name))) { |
---|
| 345 | return true; |
---|
| 346 | } else { |
---|
[1] | 347 | $this->addError($form_name, $msg); |
---|
| 348 | return false; |
---|
| 349 | } |
---|
| 350 | } |
---|
[42] | 351 | |
---|
[1] | 352 | /** |
---|
| 353 | * Check whether input matches the specified perl regular expression |
---|
[42] | 354 | * pattern. |
---|
[1] | 355 | * |
---|
| 356 | * @param string $form_name the name of the incoming form variable |
---|
| 357 | * @param int $regex perl regex that the string must match |
---|
[144] | 358 | * @param bool $valid_on_match set to false to be valid if match, or true |
---|
[1] | 359 | * to be valid on no match |
---|
| 360 | * @param string $msg the message to display on error |
---|
| 361 | * |
---|
| 362 | * @return bool true if value passes regex test |
---|
| 363 | */ |
---|
[144] | 364 | function checkRegex($form_name, $regex, $valid_on_match, $msg='') |
---|
[1] | 365 | { |
---|
[144] | 366 | if (parent::checkRegex(getFormData($form_name), $regex, $valid_on_match)) { |
---|
| 367 | return true; |
---|
[1] | 368 | } else { |
---|
[144] | 369 | $this->addError($form_name, $msg); |
---|
| 370 | return false; |
---|
[1] | 371 | } |
---|
| 372 | } |
---|
[42] | 373 | |
---|
[1] | 374 | /** |
---|
| 375 | * Tests if the string length is between specified values. Whitespace excluded for min. |
---|
| 376 | * |
---|
| 377 | * @param string $form_name the name of the incoming form variable |
---|
| 378 | * @param int $min minimum length of string, inclusive |
---|
| 379 | * @param int $max maximum length of string, inclusive |
---|
| 380 | * @param string $msg the message to display on error |
---|
| 381 | * |
---|
| 382 | * @return bool true if string length is within given boundaries |
---|
| 383 | */ |
---|
| 384 | function stringLength($form_name, $min, $max, $msg='') |
---|
| 385 | { |
---|
[144] | 386 | if (parent::stringLength(getFormData($form_name), $min, $max)) { |
---|
| 387 | return true; |
---|
| 388 | } else { |
---|
[1] | 389 | $this->addError($form_name, $msg); |
---|
| 390 | return false; |
---|
| 391 | } |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | /** |
---|
| 395 | * Check whether input is within a valid numeric range. |
---|
| 396 | * |
---|
| 397 | * @param string $form_name the name of the incoming form variable |
---|
| 398 | * @param int $min minimum value of number, inclusive |
---|
| 399 | * @param int $max maximum value of number, inclusive |
---|
| 400 | * @param string $msg the message to display on error |
---|
| 401 | * |
---|
| 402 | * @return bool true if no errors found, false otherwise |
---|
| 403 | */ |
---|
| 404 | function numericRange($form_name, $min, $max, $msg='') |
---|
| 405 | { |
---|
[144] | 406 | if (parent::numericRange(getFormData($form_name), $min, $max)) { |
---|
[1] | 407 | return true; |
---|
| 408 | } else { |
---|
[144] | 409 | $this->addError($form_name, $msg); |
---|
[1] | 410 | return false; |
---|
| 411 | } |
---|
| 412 | } |
---|
| 413 | |
---|
| 414 | /** |
---|
[23] | 415 | * Validates an email address based on the recommendations in RFC 3696. |
---|
[42] | 416 | * Is more loose than restrictive, to allow the many valid variants of |
---|
[23] | 417 | * email addresses while catching the most common mistakes. |
---|
| 418 | * http://www.faqs.org/rfcs/rfc822.html |
---|
| 419 | * http://www.faqs.org/rfcs/rfc2822.html |
---|
| 420 | * http://www.faqs.org/rfcs/rfc3696.html |
---|
| 421 | * http://www.faqs.org/rfcs/rfc1035.html |
---|
[1] | 422 | * |
---|
[23] | 423 | * @access public |
---|
| 424 | * @param string $form_name The name of the incoming form variable. |
---|
| 425 | * @return bool Validity of address. |
---|
| 426 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
[1] | 427 | */ |
---|
[23] | 428 | function validateEmail($form_name) |
---|
[1] | 429 | { |
---|
[136] | 430 | $app =& App::getInstance(); |
---|
[144] | 431 | |
---|
[1] | 432 | $email = getFormData($form_name); |
---|
[144] | 433 | |
---|
[1] | 434 | if ('' == trim($email)) { |
---|
[144] | 435 | // No email address provided, and that's okay |
---|
| 436 | return true; |
---|
[1] | 437 | } |
---|
[23] | 438 | |
---|
[144] | 439 | // Validator::validateEmail() returns a value that relates to the VALIDATE_EMAIL_* constants (defined in Validator.inc.php). |
---|
| 440 | switch (parent::validateEmail($email)) { |
---|
| 441 | case VALIDATE_EMAIL_REGEX_FAIL: |
---|
| 442 | // Failed regex match. |
---|
| 443 | $this->addError($form_name, sprintf(_("<em>%s</em> is not a valid email address."), oTxt($email))); |
---|
[136] | 444 | $app->logMsg(sprintf('The email address %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__); |
---|
[23] | 445 | return false; |
---|
[144] | 446 | break; |
---|
| 447 | case VALIDATE_EMAIL_LENGTH_FAIL : |
---|
| 448 | // Failed length requirements. |
---|
| 449 | $this->addError($form_name, sprintf(_("<em>Email address</em> must contain less than 256 characters."), oTxt($email))); |
---|
[136] | 450 | $app->logMsg(sprintf('The email address %s must contain less than 256 characters.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__); |
---|
[1] | 451 | return false; |
---|
[144] | 452 | break; |
---|
| 453 | case VALIDATE_EMAIL_MX_FAIL : |
---|
| 454 | // Failed MX record test. |
---|
| 455 | $this->addError($form_name, sprintf(_("<em>%s</em> is not a valid email domain name"), oTxt($domain))); |
---|
[136] | 456 | $app->logMsg(sprintf('The email address %s contains an invalid email domain name (%s).', getFormData($form_name), $domain), LOG_INFO, __FILE__, __LINE__); |
---|
[23] | 457 | return false; |
---|
[144] | 458 | break; |
---|
| 459 | case VALIDATE_EMAIL_SUCCESS : |
---|
| 460 | default : |
---|
| 461 | return true; |
---|
| 462 | break; |
---|
[1] | 463 | } |
---|
| 464 | } |
---|
| 465 | |
---|
| 466 | /** |
---|
| 467 | * Check whether input is a valid phone number. Notice: it is now set |
---|
| 468 | * to allow characters like - or () or + so people can type in a phone |
---|
[144] | 469 | * number that looks like: +1 (530) 555-1212 |
---|
[1] | 470 | * |
---|
| 471 | * @param string $form_name the name of the incoming form variable |
---|
| 472 | * |
---|
| 473 | * @return bool true if no errors found, false otherwise |
---|
| 474 | */ |
---|
| 475 | function validatePhone($form_name) |
---|
| 476 | { |
---|
| 477 | $phone = getFormData($form_name); |
---|
[42] | 478 | |
---|
[144] | 479 | return ( |
---|
| 480 | $this->checkRegex($form_name, '/^[0-9 +().-]*$/', true, sprintf(_("The phone number <em>%s</em> is not valid."), $phone)) |
---|
| 481 | && $this->stringLength($form_name, 0, 25, sprintf(_("The phone number <em>%s</em> is too long"), $phone)) |
---|
| 482 | ); |
---|
[1] | 483 | } |
---|
| 484 | |
---|
| 485 | /** |
---|
| 486 | * Verifies that date can be processed by the strtotime function. |
---|
| 487 | * |
---|
| 488 | * @param string $form_name the name of the incoming form variable |
---|
| 489 | * @param string $msg the message to display on error |
---|
| 490 | * |
---|
| 491 | * @return bool true if no errors found, false otherwise |
---|
| 492 | */ |
---|
| 493 | function validateStrDate($form_name, $msg='') |
---|
| 494 | { |
---|
[144] | 495 | $app =& App::getInstance(); |
---|
| 496 | |
---|
| 497 | if (parent::validateStrDate(getFormData($form_name))) { |
---|
| 498 | return true; |
---|
| 499 | } else { |
---|
[1] | 500 | $this->addError($form_name, $msg); |
---|
[136] | 501 | $app->logMsg(sprintf('The string date %s is not valid.', getFormData($form_name)), LOG_DEBUG, __FILE__, __LINE__); |
---|
[1] | 502 | return false; |
---|
| 503 | } |
---|
| 504 | } |
---|
[42] | 505 | |
---|
| 506 | |
---|
[1] | 507 | /** |
---|
| 508 | * Verifies credit card number. |
---|
| 509 | * |
---|
| 510 | * @param string $form_name The name of the incoming form variable. |
---|
[144] | 511 | * @param string $cc_type Optional, card type to do specific checks. One of the CC_TYPE_* constants. |
---|
[1] | 512 | * |
---|
| 513 | * @return bool true if no errors found, false otherwise |
---|
| 514 | */ |
---|
[144] | 515 | function validateCCNumber($form_name, $cc_type=null) |
---|
[1] | 516 | { |
---|
[144] | 517 | $cc_num = getFormData($form_name); |
---|
| 518 | |
---|
| 519 | if (parent::validateCCNumber($cc_num, $cc_type)) { |
---|
[1] | 520 | return true; |
---|
| 521 | } else { |
---|
[144] | 522 | $this->addError($form_name, sprintf(_("<em>%s</em> is not a valid credit card number."), $cc_num)); |
---|
[1] | 523 | return false; |
---|
| 524 | } |
---|
| 525 | } |
---|
| 526 | |
---|
| 527 | /** |
---|
[136] | 528 | * Check whether a file was selected for uploading. If file is missing, it's an error. |
---|
[1] | 529 | * |
---|
| 530 | * @param string $form_name the name of the incoming form variable |
---|
| 531 | * @param string $msg the message to display on error |
---|
| 532 | * |
---|
| 533 | * @return bool true if no errors found, false otherwise |
---|
| 534 | */ |
---|
[144] | 535 | function fileUploaded($form_name, $msg='') |
---|
[1] | 536 | { |
---|
[144] | 537 | if (parent::fileUploaded($form_name)) { |
---|
| 538 | return true; |
---|
| 539 | } else { |
---|
[1] | 540 | $this->addError($form_name, $msg); |
---|
| 541 | return false; |
---|
| 542 | } |
---|
| 543 | } |
---|
[42] | 544 | |
---|
[1] | 545 | } // THE END |
---|
| 546 | |
---|
| 547 | ?> |
---|