示例#1
0
 /**
  * Gets value of the field from $_REQUEST or $_SESSION (is some REQUEST values
  * needs to be stored by scenario). Also it takes values from $_GET or $_POST
  * separately if second parameter is passed.
  *
  * @param mixed $fieldName String name of the field or complex hierarchy name.
  * @param string $source Http::GET or Http::POST constant.
  *
  * @return mixed Value of the field, NULL otherwise.
  */
 public static function getFieldValue($fieldName, $source = null)
 {
     $value = null;
     try {
         switch ($source) {
             case Http::GET:
                 $value = Naming::getValueByComplexName($_GET, $fieldName);
                 break;
             case Http::POST:
                 $value = Naming::getValueByComplexName($_POST, $fieldName);
                 break;
             default:
                 $value = Naming::getValueByComplexName($_REQUEST, $fieldName);
         }
     } catch (\Exception $ex) {
         try {
             if (Session::exists('_post')) {
                 $value = Naming::getValueByComplexName(Session::get('_post'), $fieldName);
             }
         } catch (\Exception $ex) {
             return null;
         }
     }
     if (!is_null($value)) {
         if (is_array($value)) {
             return $value;
         } elseif (is_int($value)) {
             return intval($value);
         }
         return $value;
     }
     return null;
 }
示例#2
0
 /**
  * Validate if captcha code is correct.
  *
  * @param string $fieldName Name of the captcha field.
  *
  * @return bool
  */
 public static function validateCaptcha($fieldName)
 {
     if (!validateNotEmpty($fieldName)) {
         return false;
     }
     if (!validateNoSpaces($fieldName)) {
         return false;
     }
     if (Request::getFieldValue($fieldName) != Session::get($fieldName)) {
         Errors::saveErrorFor($fieldName, \__ERRORS::INVALID_CAPTCHA_CODE);
         return false;
     }
     return true;
 }