Beispiel #1
0
 /**
  * @param CM_Frontend_Environment $environment
  * @param string                  $userInput
  * @throws CM_Exception_FormFieldValidation
  * @return CM_Model_Location
  */
 public function validate(CM_Frontend_Environment $environment, $userInput)
 {
     $value = parent::validate($environment, $userInput);
     $value = CM_Params::jsonDecode($value);
     $location = CM_Model_Location::fromArray($value);
     if ($location->getLevel() < $this->_options['levelMin'] || $location->getLevel() > $this->_options['levelMax']) {
         throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Invalid location level.'));
     }
     return $location;
 }
Beispiel #2
0
 /**
  * @param CM_Frontend_Environment $environment
  * @param string                  $userInput
  * @throws CM_Exception_FormFieldValidation
  * @return CM_Model_Location
  */
 public function validate(CM_Frontend_Environment $environment, $userInput)
 {
     $value = parent::validate($environment, $userInput);
     if (!preg_match('/^(\\d+)\\.(\\d+)$/', $value, $matches)) {
         throw new CM_Exception_FormFieldValidation('Invalid input format');
     }
     $level = $matches[1];
     $id = $matches[2];
     if ($level < $this->_options['levelMin'] || $level > $this->_options['levelMax']) {
         throw new CM_Exception_FormFieldValidation('Invalid location level.');
     }
     return new CM_Model_Location($level, $id);
 }