예제 #1
0
	/**
	 * Validator:
	 * Validates $value for $field->required and other rules
	 * Override
	 *
	 * @param  moscomprofilerFields  $field
	 * @param  moscomprofilerUser    $user        RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit)
	 * @param  string                $columnName  Column to validate
	 * @param  string                $value       (RETURNED:) Value to validate, Returned Modified if needed !
	 * @param  array                 $postdata    Typically $_POST (but not necessarily), filtering required.
	 * @param  string                $reason      'edit' for save profile edit, 'register' for registration, 'search' for searches
	 * @return boolean                            True if validate, $this->_setErrorMSG if False
	 */
	function validate( &$field, &$user, $columnName, &$value, &$postdata, $reason ) {
		$validate	=	parent::validate( $field, $user, $columnName, $value, $postdata, $reason );
		if ( $validate && ( $value !== null ) ) {
			$year						=	substr( $value, 0, 4 );
			if ( ( $year == '' ) || ( $year == '0000' ) ) {
				if ( $this->_isRequired( $field, $user, $reason ) ) {
					$this->_setValidationError( $field, $user, $reason, cbUnHtmlspecialchars(_UE_REQUIRED_ERROR) );
					return false;
				}
			} else {
				// check range:
				list( $yMin, $yMax )		=	$this->_yearsRange( $field, 0 );
				if ( ( $year < $yMin ) || ( $year > $yMax ) ) {
					$this->_setValidationError( $field, $user, $reason, sprintf( _UE_YEAR_NOT_IN_RANGE, (int) $year, (int) $yMin, (int) $yMax ) );
					$validate				=	false;
				}
			}
		}
		return $validate;
	}
예제 #2
0
 /**
  * Validator:
  * Validates $value for $field->required and other rules
  * Override
  *
  * @param  FieldTable  $field
  * @param  UserTable   $user        RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit)
  * @param  string      $columnName  Column to validate
  * @param  string      $value       (RETURNED:) Value to validate, Returned Modified if needed !
  * @param  array       $postdata    Typically $_POST (but not necessarily), filtering required.
  * @param  string      $reason      'edit' for save profile edit, 'register' for registration, 'search' for searches
  * @return boolean                  True if validate, $this->_setErrorMSG if False
  */
 public function validate(&$field, &$user, $columnName, &$value, &$postdata, $reason)
 {
     $validate = parent::validate($field, $user, $columnName, $value, $postdata, $reason);
     if ($validate && $value !== null) {
         $year = substr($value, 0, 4);
         if ($year == '' || $year == '0000') {
             if ($this->_isRequired($field, $user, $reason)) {
                 $this->_setValidationError($field, $user, $reason, cbUnHtmlspecialchars(CBTxt::T('UE_REQUIRED_ERROR', 'This field is required!')));
                 $validate = false;
             }
         } else {
             // check range:
             list($yMin, $yMax) = $this->_yearsRange($field, 0);
             if ($year < $yMin || $year > $yMax) {
                 $this->_setValidationError($field, $user, $reason, sprintf(CBTxt::T('UE_YEAR_NOT_IN_RANGE', 'Year %s is not between %s and %s'), (int) $year, (int) $yMin, (int) $yMax));
                 $validate = false;
             }
         }
     }
     return $validate;
 }
예제 #3
0
	/**
	 * Validator:
	 * Validates $value for $field->required and other rules
	 * Override
	 *
	 * @param  FieldTable  $field
	 * @param  UserTable   $user        RETURNED populated: touch only variables related to saving this field (also when not validating for showing re-edit)
	 * @param  string      $columnName  Column to validate
	 * @param  string      $value       (RETURNED:) Value to validate, Returned Modified if needed !
	 * @param  array       $postdata    Typically $_POST (but not necessarily), filtering required.
	 * @param  string      $reason      'edit' for save user edit, 'register' for save registration
	 * @return boolean                  True if validate, $this->_setErrorMSG if False
	 */
	public function validate( &$field, &$user, $columnName, &$value, &$postdata, $reason )
	{
		if ( ( ! Application::Cms()->getClientId() ) && ( ! Application::MyUser()->isGlobalModerator() ) && in_array( $reason, array( 'register', 'edit' ) ) ) {
			if ( parent::validate( $field, $user, $columnName, $value, $postdata, $reason ) ) {
				$captcha	=	cbantispamCaptcha::getInstance( $field->get( 'name' ), $field->params->get( 'cbantispam_captcha_mode', null ) );

				if ( ! $captcha->validateCaptcha() ) {
					$this->_setValidationError( $field, $user, $reason, ( $captcha->error ? $captcha->error : CBTxt::T( 'Invalid Captcha Code' ) ) );

					return false;
				}
			}
		}

		return true;
	}