Пример #1
0
 public function validate(CM_Frontend_Environment $environment, $userInput)
 {
     $userInput = parent::validate($environment, $userInput);
     if (false === filter_var($userInput, FILTER_VALIDATE_URL)) {
         throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Invalid url'));
     }
     return $userInput;
 }
Пример #2
0
 public function validate(CM_Frontend_Environment $environment, $userInput)
 {
     $userInput = parent::validate($environment, $userInput);
     if (!is_numeric($userInput)) {
         throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Not numeric'));
     }
     return (double) $userInput;
 }
Пример #3
0
 public function validate(CM_Frontend_Environment $environment, $userInput)
 {
     $userInput = parent::validate($environment, $userInput);
     $emailVerification = $this->_getEmailVerification();
     if (!$emailVerification->isValid($userInput)) {
         throw new CM_Exception_FormFieldValidation('Invalid email address');
     }
     return $userInput;
 }
Пример #4
0
 public function validate(CM_Frontend_Environment $environment, $userInput)
 {
     $userInput = parent::validate($environment, $userInput);
     if (!preg_match('/^(\\d{1,2})(?:[:\\.](\\d{2}))?$/', $userInput, $matches)) {
         throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Illegal time format.'));
     }
     $hour = (int) $matches[1];
     $minute = array_key_exists(2, $matches) ? $matches[2] : 0;
     if ($hour > 24 || $minute > 60 || $hour === 24 && $minute > 0) {
         throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Illegal time format.'));
     }
     return new DateInterval('PT' . $hour . 'H' . $minute . 'M');
 }
Пример #5
0
 public function validate(CM_Frontend_Environment $environment, $userInput)
 {
     $userInput = parent::validate($environment, $userInput);
     if (!is_numeric($userInput)) {
         throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Not numeric'));
     }
     $userInput = (double) $userInput;
     if (isset($this->_options['min']) && $userInput < $this->_options['min']) {
         throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Value cannot be lesser than ${minimum}.', ['minimum' => $this->_options['min']]));
     }
     if (isset($this->_options['max']) && $userInput > $this->_options['max']) {
         throw new CM_Exception_FormFieldValidation(new CM_I18n_Phrase('Value cannot be greater than ${maximum}', ['maximum' => $this->_options['max']]));
     }
     return $userInput;
 }
Пример #6
0
 public function testValidateBadwords()
 {
     $badwordsList = new CM_Paging_ContentList_Badwords();
     $field = new CM_FormField_Text(['name' => 'foo', 'forbidBadwords' => true]);
     $environment = new CM_Frontend_Environment();
     $render = new CM_Frontend_Render();
     try {
         $field->validate($environment, 'foo');
     } catch (CM_Exception_FormFieldValidation $ex) {
         $this->fail('Expected value not to be a badword');
     }
     $badwordsList->add('foo');
     try {
         $field->validate($environment, 'foo');
         $this->fail('Expected value to be a badword');
     } catch (CM_Exception_FormFieldValidation $ex) {
         $this->assertContains('The word `foo` is not allowed', $ex->getMessagePublic($render));
     }
     $field = new CM_FormField_Text(['name' => 'foo', 'forbidBadwords' => false]);
     try {
         $field->validate($environment, 'foo');
     } catch (CM_Exception_FormFieldValidation $ex) {
         $this->fail('Badword-validation shouldn\'t be activated');
     }
 }