Changeset 468 for trunk/lib/FormValidator.inc.php
- Timestamp:
- Feb 20, 2014 3:03:59 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property
svn:mergeinfo
set to
/branches/eli_branch merged eligible
-
Property
svn:mergeinfo
set to
-
trunk/lib/FormValidator.inc.php
r459 r468 58 58 require_once 'codebase/lib/Validator.inc.php'; 59 59 60 class FormValidator extends Validator{60 class FormValidator { 61 61 62 62 // Class parameters. 63 var$_params = array(63 private $_params = array( 64 64 'error' => ' sc-msg-error ', 65 65 'warning' => ' sc-msg-warning ', … … 69 69 70 70 // Array filling with error messages. 71 var$errors = array();71 public $errors = array(); 72 72 73 73 /** … … 77 77 * @param array $params Array of parameters (key => val pairs). 78 78 */ 79 function setParam($params)79 public function setParam($params) 80 80 { 81 81 $app =& App::getInstance(); … … 96 96 * @return mixed Configured parameter value. 97 97 */ 98 function getParam($param)98 public function getParam($param) 99 99 { 100 100 $app =& App::getInstance(); … … 115 115 * vals: the message to display for that error 116 116 */ 117 function getErrorList()117 public function getErrorList() 118 118 { 119 119 return $this->errors; … … 130 130 * @param string $line __LINE__. 131 131 */ 132 function addError($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null)132 public function addError($form_name, $msg='', $type=MSG_ERR, $file=null, $line=null) 133 133 { 134 134 $this->errors[] = array( … … 149 149 * a variable of $form_name, false otherwise 150 150 */ 151 function anyErrors($form_name=null)151 public function anyErrors($form_name=null) 152 152 { 153 153 if (isset($form_name)) { … … 166 166 * Reset the error list. 167 167 */ 168 function resetErrorList()168 public function resetErrorList() 169 169 { 170 170 $this->errors = array(); … … 182 182 * @since 15 Jul 2005 01:39:14 183 183 */ 184 function printErrorMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg-formvalidator')184 public function printErrorMessages($above='', $below='', $print_gotohash_js=false, $hash='sc-msg-formvalidator') 185 185 { 186 186 $app =& App::getInstance(); … … 238 238 * not provided, use default. 239 239 */ 240 function err($form_name, $marker=null)240 public function err($form_name, $marker=null) 241 241 { 242 242 if (false !== ($type = $this->anyErrors($form_name))) { … … 274 274 * @return bool true if form is not empty, false otherwise. 275 275 */ 276 function notEmpty($form_name, $msg='')277 { 278 if ( parent::notEmpty(getFormData($form_name))) {276 public function notEmpty($form_name, $msg='') 277 { 278 if (Validator::notEmpty(getFormData($form_name))) { 279 279 return true; 280 280 } else { … … 290 290 * @since 03 Jun 2006 22:56:46 291 291 */ 292 function isEmpty($form_name, $msg='')292 public function isEmpty($form_name, $msg='') 293 293 { 294 294 $this->notEmpty($form_name, $msg); … … 303 303 * @return bool true if form is a string, false otherwise. 304 304 */ 305 function isString($form_name, $msg='')306 { 307 if ( parent::isString(getFormData($form_name))) {305 public function isString($form_name, $msg='') 306 { 307 if (Validator::isString(getFormData($form_name))) { 308 308 return true; 309 309 } else { … … 321 321 * @return bool true if no errors found, false otherwise 322 322 */ 323 function isNumber($form_name, $msg='')324 { 325 if ( parent::isNumber(getFormData($form_name))) {323 public function isNumber($form_name, $msg='') 324 { 325 if (Validator::isNumber(getFormData($form_name))) { 326 326 return true; 327 327 } else { … … 340 340 * @return bool true if value is an integer 341 341 */ 342 function isInteger($form_name, $msg='', $negative_ok=false)343 { 344 if ( parent::isInteger(getFormData($form_name), $negative_ok)) {342 public function isInteger($form_name, $msg='', $negative_ok=false) 343 { 344 if (Validator::isInteger(getFormData($form_name), $negative_ok)) { 345 345 return true; 346 346 } else { … … 360 360 * @return bool true if value is a float 361 361 */ 362 function isFloat($form_name, $msg='', $negative_ok=false)363 { 364 if ( parent::isFloat(getFormData($form_name), $negative_ok)) {362 public function isFloat($form_name, $msg='', $negative_ok=false) 363 { 364 if (Validator::isFloat(getFormData($form_name), $negative_ok)) { 365 365 return true; 366 366 } else { … … 378 378 * @return bool true if value is a float 379 379 */ 380 function isArray($form_name, $msg='')381 { 382 if ( parent::isArray(getFormData($form_name))) {380 public function isArray($form_name, $msg='') 381 { 382 if (Validator::isArray(getFormData($form_name))) { 383 383 return true; 384 384 } else { … … 399 399 * @return bool true if value passes regex test 400 400 */ 401 function checkRegex($form_name, $regex, $valid_on_match, $msg='')402 { 403 if ( parent::checkRegex(getFormData($form_name), $regex, $valid_on_match)) {401 public function checkRegex($form_name, $regex, $valid_on_match=true, $msg='') 402 { 403 if (Validator::checkRegex(getFormData($form_name), $regex, $valid_on_match)) { 404 404 return true; 405 405 } else { … … 419 419 * @return bool true if string length is within given boundaries 420 420 */ 421 function stringLength($form_name, $min, $max, $msg='')422 { 423 if ( parent::stringLength(getFormData($form_name), $min, $max)) {421 public function stringLength($form_name, $min, $max, $msg='') 422 { 423 if (Validator::stringLength(getFormData($form_name), $min, $max)) { 424 424 return true; 425 425 } else { … … 439 439 * @return bool true if no errors found, false otherwise 440 440 */ 441 function numericRange($form_name, $min, $max, $msg='')442 { 443 if ( parent::numericRange(getFormData($form_name), $min, $max)) {441 public function numericRange($form_name, $min, $max, $msg='') 442 { 443 if (Validator::numericRange(getFormData($form_name), $min, $max)) { 444 444 return true; 445 445 } else { … … 463 463 * @author Quinn Comendant <quinn@strangecode.com> 464 464 */ 465 function validateEmail($form_name)465 public function validateEmail($form_name, $strict=false) 466 466 { 467 467 $app =& App::getInstance(); … … 474 474 } 475 475 476 // Validator::validateEmail() returns a value that relates to the V ALIDATE_EMAIL_* constants (defined in Validator.inc.php).477 switch ( parent::validateEmail($email)) {478 case V ALIDATE_EMAIL_REGEX_FAIL:476 // Validator::validateEmail() returns a value that relates to the Validate::EMAIL_* constants (defined in Validator.inc.php). 477 switch (Validator::validateEmail($email, $strict)) { 478 case Validator::EMAIL_REGEX_FAIL: 479 479 // Failed regex match. 480 480 $this->addError($form_name, sprintf(_("The email address <em>%s</em> is formatted incorrectly."), oTxt($email))); 481 481 $app->logMsg(sprintf('The email address %s is not valid.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__); 482 482 return false; 483 break; 484 485 case VALIDATE_EMAIL_LENGTH_FAIL : 483 484 case Validator::EMAIL_LENGTH_FAIL : 486 485 // Failed length requirements. 487 486 $this->addError($form_name, sprintf(_("The email address <em>%s</em> is too long (email addresses must have fewer than 256 characters)."), oTxt($email))); 488 487 $app->logMsg(sprintf('The email address %s must contain less than 256 characters.', oTxt($email)), LOG_DEBUG, __FILE__, __LINE__); 489 488 return false; 490 break; 491 492 case VALIDATE_EMAIL_MX_FAIL : 489 490 case Validator::EMAIL_MX_FAIL : 493 491 // Failed MX record test. 494 492 $this->addError($form_name, sprintf(_("The email address <em>%s</em> does not have a valid domain name"), oTxt($email))); 495 493 $app->logMsg(sprintf('The email address %s does not have a valid domain name.', oTxt($email)), LOG_INFO, __FILE__, __LINE__); 496 494 return false; 497 break; 498 499 case VALIDATE_EMAIL_SUCCESS : 495 496 case Validator::EMAIL_SUCCESS : 500 497 default : 501 498 return true; 502 break;503 499 } 504 500 } … … 513 509 * @return bool true if no errors found, false otherwise 514 510 */ 515 function validatePhone($form_name) 516 { 511 public function validatePhone($form_name) 512 { 513 $app =& App::getInstance(); 514 517 515 $phone = getFormData($form_name); 518 516 519 return ( 520 $this->checkRegex($form_name, '/^[0-9 +().-]*$/', true, sprintf(_("The phone number <em>%s</em> is not valid."), $phone)) 521 && $this->stringLength($form_name, 0, 25, sprintf(_("The phone number <em>%s</em> is too long"), $phone)) 522 ); 517 // Validator::validateEmail() returns a value that relates to the Validate::PHONE_* constants (defined in Validator.inc.php). 518 switch (Validator::validatePhone($phone)) { 519 case Validator::PHONE_REGEX_FAIL: 520 // Failed regex match. 521 $this->addError($form_name, sprintf(_("The phone number <em>%s</em> is not valid."), oTxt($phone))); 522 $app->logMsg(sprintf('The phone number %s is not valid.', oTxt($phone)), LOG_DEBUG, __FILE__, __LINE__); 523 return false; 524 525 case Validator::PHONE_LENGTH_FAIL : 526 // Failed length requirements. 527 $this->addError($form_name, sprintf(_("The phone number <em>%s</em> is too long (phone number must have fewer than 25 characters)."), oTxt($phone))); 528 $app->logMsg(sprintf('The phone number %s must contain less than 256 characters.', oTxt($phone)), LOG_DEBUG, __FILE__, __LINE__); 529 return false; 530 531 case Validator::PHONE_SUCCESS : 532 default : 533 return true; 534 } 523 535 } 524 536 … … 531 543 * @return bool true if no errors found, false otherwise 532 544 */ 533 function validateStrDate($form_name, $msg='')545 public function validateStrDate($form_name, $msg='') 534 546 { 535 547 $app =& App::getInstance(); 536 548 537 if ( parent::validateStrDate(getFormData($form_name, ''))) {549 if (Validator::validateStrDate(getFormData($form_name, ''))) { 538 550 return true; 539 551 } else { … … 550 562 * 551 563 * @param string $form_name The name of the incoming form variable. 552 * @param string $cc_type Optional, card type to do specific checks. One of the CC_TYPE_* constants.564 * @param string $cc_type Optional, card type to do specific checks. One of the Validator::CC_TYPE_* constants. 553 565 * 554 566 * @return bool true if no errors found, false otherwise 555 567 */ 556 function validateCCNumber($form_name, $cc_type=null)568 public function validateCCNumber($form_name, $cc_type=null) 557 569 { 558 570 $cc_num = getFormData($form_name); 559 571 560 if ( parent::validateCCNumber($cc_num, $cc_type)) {572 if (Validator::validateCCNumber($cc_num, $cc_type)) { 561 573 return true; 562 574 } else { … … 574 586 * @return bool true if no errors found, false otherwise 575 587 */ 576 function fileUploaded($form_name, $msg='')577 { 578 if ( parent::fileUploaded($form_name)) {588 public function fileUploaded($form_name, $msg='') 589 { 590 if (Validator::fileUploaded($form_name)) { 579 591 return true; 580 592 } else { … … 586 598 } // THE END 587 599 588 ?>
Note: See TracChangeset
for help on using the changeset viewer.