本文整理汇总了PHP中TextField::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP TextField::validate方法的具体用法?PHP TextField::validate怎么用?PHP TextField::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextField
的用法示例。
在下文中一共展示了TextField::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
/**
* 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);
}
}
示例2: testRegexpPrice
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);
}
示例3: validate
/**
* 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."));
}
}
示例4: validate
/**
* 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.");
}
}
示例5: validate
/**
* 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);
}
}
示例6: testMaxLengthValidationSuccess
/**
* 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);
}
示例7: validate
public function validate()
{
if (!parent::validate()) {
array_push($this->errors, "Invalid email address entered");
$this->error = true;
return false;
} else {
return true;
}
}
示例8: validate
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;
}
示例9: validate
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;
}
示例10: validate
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;
}
示例11: validate
/**
* 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.");
}
示例12: validate
/**
* 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();
}
示例13: validate
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;
}
示例14: validate
/**
* 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();
}
示例15: handle
/**
* {@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();
}