Example #1
0
 /**
  * Validates that the value matches the regular expression.
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     if (!preg_match($this->regex, $value, $this->matches)) {
         throw new ValidationError($this->message);
     }
 }
 public function testRegexpPrice()
 {
     \Input::setPost('test_rgxp_price', 'foobar');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertTrue($objWidget->hasErrors());
     unset($objWidget);
     \Input::setPost('test_rgxp_price', '20.00');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertFalse($objWidget->hasErrors());
     unset($objWidget);
     \Input::setPost('test_rgxp_price', '20');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertFalse($objWidget->hasErrors());
     unset($objWidget);
     \Input::setPost('test_rgxp_price', '-20');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertFalse($objWidget->hasErrors());
     unset($objWidget);
     \Input::setPost('test_rgxp_price', '20.-');
     $objWidget = new \TextField(array('name' => 'test_rgxp_price'));
     $objWidget->rgxp = 'price';
     $objWidget->validate();
     $this->assertFalse($objWidget->hasErrors());
     unset($objWidget);
 }
Example #3
0
 /**
  * Validates that the value is a valid email address.
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     if (!preg_match('@^([-_\\.a-zA-Z0-9]+)\\@(([-_\\.a-zA-Z0-9]+)\\.)+[-_\\.a-zA-Z0-9]+$@', $value)) {
         throw new ValidationError(__("Invalid email address."));
     }
 }
Example #4
0
 /**
  * Validates the the value is a valid URL (mostly).
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     if (!preg_match('@^(http|ftp)s?://(\\w+(:\\w+)?\\@)?(([-_\\.a-zA-Z0-9]+)\\.)+[-_\\.a-zA-Z0-9]+(\\w*)@', $value)) {
         throw new ValidationError("Invalid URL.");
     }
 }
Example #5
0
 /**
  * Validates that the value matches the sscanf format.
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     $this->matched = sscanf($value, $this->format);
     if (count($this->matched) === 0) {
         throw new ValidationError($this->message);
     }
 }
 /**
  * Tests the TextField Max Length Validation Success
  */
 public function testMaxLengthValidationSuccess()
 {
     $textField = new TextField('TestField');
     $textField->setMaxLength(5);
     $textField->setValue("John");
     // 4 characters, so should pass
     $result = $textField->validate(new RequiredFields());
     $this->assertTrue($result);
 }
Example #7
0
 public function validate()
 {
     if (!parent::validate()) {
         array_push($this->errors, "Invalid email address entered");
         $this->error = true;
         return false;
     } else {
         return true;
     }
 }
Example #8
0
 public function validate()
 {
     if (!parent::validate()) {
         return false;
     }
     if ($this->value && filter_var($this->value, FILTER_VALIDATE_EMAIL) === false) {
         $this->errorMessage = "Please enter a valid e-mail address.";
         return false;
     }
     return true;
 }
Example #9
0
 public function validate()
 {
     if ($this->validate and is_array($this->validate)) {
         return parent::validate();
     } else {
         if ($this->min and !v::min($this->result(), $this->min)) {
             return false;
         }
         if ($this->max and !v::max($this->result(), $this->max)) {
             return false;
         }
     }
     return true;
 }
Example #10
0
 public function validate($object, $field_name)
 {
     if (!parent::validate($object, $field_name)) {
         return FALSE;
     }
     $value = $object->{$field_name};
     if (empty($value)) {
         return TRUE;
     }
     if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
         $this->setError('wrong_value', 'Field "' . $this->getLabel() . '" (' . $field_name . ') is not a valid mail address!');
         return FALSE;
     }
     return TRUE;
 }
Example #11
0
 /**
  * Validates that the value is parsable as a date/time value.
  * @author Jeff Ober
  * @param string $value
  * @return null
  * @throws ValidationError
  **/
 public function validate($value)
 {
     parent::validate($value);
     //if (!strtotime($value))
     //throw new ValidationError("Date/time format not recognized.");
 }
Example #12
0
 /**
  * Validate input and set value
  */
 public function validate()
 {
     $varInput = $this->validator(deserialize($this->getPost($this->strName)));
     $this->saveTags(implode(",", array_filter(trimsplit(",", $varInput), 'strlen')));
     parent::validate();
 }
Example #13
0
 public function validate($data)
 {
     $url = $data[$this->name];
     $filtered_url = filter_var($url, FILTER_VALIDATE_URL);
     if ($filtered_url != $url) {
         $this->error("You must supply a valid URL.");
     } else {
         parent::validate($data);
     }
     return !$this->hasError;
 }
Example #14
0
 /**
  * Validates field's errors and returns them as array
  * @return array
  */
 public function validate()
 {
     if (is_null($this->size)) {
         $this->_addError("required option max_length was not set");
     }
     return parent::validate();
 }
 /**
  * {@inheritdoc}
  */
 public function handle(\Input $input)
 {
     /** @var RootPackage $rootPackage */
     $rootPackage = $this->composer->getPackage();
     /** @var Config $config */
     $config = $this->composer->getConfig();
     $minimumStability = new \SelectMenu(array('id' => 'minimum-stability', 'name' => 'minimum-stability', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_minimum_stability'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_minimum_stability'][1], 'options' => array(array('value' => 'stable', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_stable']), array('value' => 'RC', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_rc']), array('value' => 'beta', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_beta']), array('value' => 'alpha', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_alpha']), array('value' => 'dev', 'label' => $GLOBALS['TL_LANG']['composer_client']['stability_dev'])), 'value' => $rootPackage->getMinimumStability(), 'class' => 'minimum-stability', 'required' => true));
     $preferStable = new \CheckBox(array('id' => 'prefer-stable', 'name' => 'prefer-stable', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_prefer_stable'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_prefer_stable'][1], 'options' => array(array('value' => '1', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_prefer_stable'][0])), 'value' => $rootPackage->getPreferStable(), 'class' => 'prefer-stable', 'required' => true));
     $preferredInstall = new \SelectMenu(array('id' => 'preferred-install', 'name' => 'preferred-install', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_preferred_install'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_preferred_install'][1], 'options' => array(array('value' => 'source', 'label' => $GLOBALS['TL_LANG']['composer_client']['install_source']), array('value' => 'dist', 'label' => $GLOBALS['TL_LANG']['composer_client']['install_dist']), array('value' => 'auto', 'label' => $GLOBALS['TL_LANG']['composer_client']['install_auto'])), 'value' => $config->get('preferred-install'), 'class' => 'preferred-install', 'required' => true));
     $configGithubOauth = $config->get('github-oauth');
     $githubOauth = new \TextField(array('id' => 'github-oauth', 'name' => 'github-oauth', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_github_oauth'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_github_oauth'][1], 'value' => $configGithubOauth['github.com'], 'class' => 'github-oauth'));
     $discardChanges = new \SelectMenu(array('id' => 'discard-changes', 'name' => 'discard-changes', 'label' => $GLOBALS['TL_LANG']['composer_client']['widget_discard_changes'][0], 'description' => $GLOBALS['TL_LANG']['composer_client']['widget_discard_changes'][1], 'options' => array(array('value' => '', 'label' => $GLOBALS['TL_LANG']['composer_client']['discard_changes_no']), array('value' => '1', 'label' => $GLOBALS['TL_LANG']['composer_client']['discard_changes_yes']), array('value' => 'stash', 'label' => $GLOBALS['TL_LANG']['composer_client']['discard_changes_stash'])), 'value' => (string) $config->get('discard-changes'), 'class' => 'github-oauth'));
     if ($input->post('FORM_SUBMIT') == 'tl_composer_settings') {
         $doSave = false;
         $json = new JsonFile(TL_ROOT . '/' . $this->configPathname);
         $config = $json->read();
         $minimumStability->validate();
         $preferStable->validate();
         $preferredInstall->validate();
         $githubOauth->validate();
         $discardChanges->validate();
         if (!$minimumStability->hasErrors()) {
             $config['minimum-stability'] = $minimumStability->value;
             $doSave = true;
         }
         if (!$preferStable->hasErrors()) {
             $config['prefer-stable'] = (bool) $preferStable->value;
             $doSave = true;
         }
         if (!$preferredInstall->hasErrors()) {
             $config['config']['preferred-install'] = $preferredInstall->value;
             $doSave = true;
         }
         if (!$githubOauth->hasErrors()) {
             if ($githubOauth->value) {
                 $config['config']['github-oauth']['github.com'] = $githubOauth->value;
             } else {
                 unset($config['config']['github-oauth']['github.com']);
                 if (empty($config['config']['github-oauth'])) {
                     unset($config['config']['github-oauth']);
                 }
             }
             $doSave = true;
         }
         if (!$discardChanges->hasErrors()) {
             if ($discardChanges->value) {
                 $config['config']['discard-changes'] = $discardChanges->value == 'stash' ? 'stash' : (bool) $discardChanges->value;
             } else {
                 unset($config['config']['discard-changes']);
             }
             $doSave = true;
         }
         if ($doSave) {
             // make a backup
             copy(TL_ROOT . '/' . $this->configPathname, TL_ROOT . '/' . $this->configPathname . '~');
             // update config file
             $json->write($config);
         }
         $this->redirect('contao/main.php?do=composer&settings=dialog');
     }
     $template = new \BackendTemplate('be_composer_client_settings');
     $template->composer = $this->composer;
     $template->minimumStability = $minimumStability;
     $template->preferStable = $preferStable;
     $template->preferredInstall = $preferredInstall;
     $template->githubOauth = $githubOauth;
     $template->discardChanges = $discardChanges;
     return $template->parse();
 }
 public function validate($validator)
 {
     if ($this->requireSelection && !$this->SourceList instanceof Closure) {
         $results = $this->results($this->value);
         if (!$results || !count($results)) {
             $validator->validationError($this->name, _t('TypeAheadField.INVALID', 'Invalid value'), 'validation', false);
             return false;
         }
     }
     return parent::validate($validator);
 }
Example #17
0
 public function validate()
 {
     parent::validate();
     if ($this->getValue() && !array_key_exists($this->getValue(), $this->choices)) {
         $this->valid = false;
         $this->errors['invalid'] = 'That is not a valid choice!';
     }
     if ($this->valid === false) {
         return false;
     }
     $this->valid = true;
     return true;
 }
Example #18
0
	/**
	 * Return the deadline widget as object
	 * @param mixed
	 * @return Widget
	 */
	protected function getDeadlineWidget($value=null)
	{
		$widget = new TextField();

		$widget->id = 'deadline';
		$widget->name = 'deadline';
		$widget->mandatory = true;
		$widget->rgxp = 'date';
		$widget->value = $value;

		$widget->label = $GLOBALS['TL_LANG']['tl_task']['deadline'][0];

		if ($GLOBALS['TL_CONFIG']['showHelp'] && $GLOBALS['TL_LANG']['tl_task']['deadline'][1] != '')
		{
			$widget->help = $GLOBALS['TL_LANG']['tl_task']['deadline'][1];
		}

		// Valiate input
		if ($this->Input->post('FORM_SUBMIT') == 'tl_tasks')
		{
			$widget->validate();

			if ($widget->hasErrors())
			{
				$this->blnSave = false;
			}
		}

		return $widget;
	}
Example #19
0
 public function validate($data)
 {
     $email = $data[$this->name];
     $filtered_email = filter_var($email, FILTER_VALIDATE_EMAIL);
     if ($filtered_email != $email) {
         $this->hasError = true;
         $this->errorText = "You must supply a valid email.";
     } else {
         parent::validate($data);
     }
     return !$this->hasError;
 }