private function clean(sfValidatorBase $v, $value) { $this->result = 'true'; try { $v->clean($value); } catch (Exception $e) { $this->result = 'false'; } $this->renderText($this->result); }
public function configure() { sfValidatorBase::setDefaultMessage('required', __('GENERAL_REQUIRED_FIELD_ERROR')); sfValidatorBase::setDefaultMessage('min_length', sprintf(__('GENERAL_FIELD_TOO_SHORT_ERROR'), '"%value%"', '%min_length%')); $items = PcTimezonePeer::doSelect(new Criteria()); $tzs = array(); foreach ($items as $item) { $tzs[$item->getLabel()] = $item->getDescription(); } $this->setWidgets(array('email' => new sfWidgetFormInputText(), 'password1' => new sfWidgetFormInputPassword(), 'password2' => new sfWidgetFormInputPassword(), 'lang' => new sfWidgetFormInputHidden(), 'tz' => new sfWidgetFormInputHidden(array('default' => self::TIMEZONE_DEFAULT_VALUE)), 'dst_on' => new sfWidgetFormInputHidden(array('default' => 0)))); $this->setValidators(array('password1' => new sfValidatorString(array('max_length' => sfConfig::get('app_password_maxLength'), 'min_length' => sfConfig::get('app_password_minLength'))), 'password2' => new sfValidatorString(array('max_length' => sfConfig::get('app_password_maxLength'), 'min_length' => sfConfig::get('app_password_minLength'))), 'tz' => new sfValidatorString(), 'lang' => new sfValidatorString(array('max_length' => 8, 'required' => false)), 'dst_on' => new sfValidatorString(array('max_length' => 1)))); $emailDomainsBlacklistedInRegistration = sfConfig::get('app_site_emailDomainsBlacklistedInRegistration'); foreach ($emailDomainsBlacklistedInRegistration as $k => $v) { $emailDomainsBlacklistedInRegistration[$k] = str_replace('.', '\\.', $v); } $emailDomainsBlacklistedInRegistration = implode('|', $emailDomainsBlacklistedInRegistration); $this->validatorSchema['email'] = new sfValidatorAnd(array(new sfValidatorEmail(array('required' => true, 'max_length' => sfConfig::get('app_email_maxLength'), 'min_length' => sfConfig::get('app_email_minLength'))), new sfValidatorRegex(array('pattern' => '/@(' . $emailDomainsBlacklistedInRegistration . ')(\\b|$)/si', 'must_match' => false), array('invalid' => 'Domain blocked - please use another email'))), array(), array()); $this->mergePostValidator(new sfValidatorSchemaCompare('password1', '==', 'password2', array(), array('invalid' => __('WEBSITE_REGISTRATION_PASSWORD_MISMATCH_ERROR')))); $this->mergePostValidator(new sfValidatorDetectingSpammersOnRegistration(null, array(), array('invalid' => __('WEBSITE_REGISTRATION_PASSWORD_MISMATCH_ERROR')))); $this->widgetSchema->setLabels(array('email' => __('WEBSITE_REGISTRATION_EMAIL_ADDRESS_LABEL'), 'password1' => __('WEBSITE_REGISTRATION_CHOOSE_PASSWORD_LABEL'), 'password2' => __('WEBSITE_REGISTRATION_REPEAT_PASSWORD_LABEL'))); $this->widgetSchema->setNameFormat('registration[%s]'); // {{{ START: anti-spam (see sfValidatorTimerAntiSpam class) $this->widgetSchema['asdf'] = new sfWidgetFormInputHidden(array(), array('value' => base64_encode(time()))); $this->validatorSchema['asdf'] = new sfValidatorTimerAntiSpam(); // }}} STOP: anti-spam }
public function configure($options = array(), $messages = array()) { $this->addOption('date_format_error', 'F jS, Y'); $this->addOption('does_occur', true); $this->setMessage('invalid', 'Date range %range% and range %item% %does_occur% overlap'); parent::configure($options, $messages); }
protected function isEmpty($value) { if (is_array($value)) { $filtered = array_filter($value); return empty($filtered); } return parent::isEmpty($value); }
public function configure($options = array(), $messages = array()) { $this->addOption('sso_key_field', 'sso_key'); $this->addOption('throw_global_error', false); $this->addRequiredOption('sso_fetcher'); $this->setMessage('invalid', 'The sso key is invalid.'); parent::configure($options, $messages); }
/** * options: * * form: Required sfForm instance to validate * * archiver: provide an archiver to sanitize results into a specific format (XML, YAML, etc). Default is array. * * throw_form_errors: whether or not to include validation errors in output * * messages: * * invalid: error message to throw if validation fails * * @param string $options * @param string $messages * @return null * @author Brent Shaffer */ protected function configure($options = array(), $messages = array()) { $this->addRequiredOption('form'); $this->addOption('throw_form_errors', true); $this->addOption('archiver'); $this->addMessage('invalid', 'Your form contains some errors'); parent::configure($options, $messages); }
/** * @see askAndValidate() */ public static function doAskAndValidate(sfTask $task, $question, sfValidatorBase $validator, array $options = array()) { if (!is_array($question)) { $question = array($question); } $options = array_merge(array('value' => null, 'attempts' => 3, 'style' => 'QUESTION'), $options); while ($options['attempts']--) { $value = is_null($options['value']) ? $task->ask(isset($error) && 'required' != $error->getCode() ? array_merge(array($error->getMessage(), ''), $question) : $question, isset($error) ? 'ERROR' : $options['style']) : $options['value']; try { $value = $validator->clean($value); return $value; } catch (sfValidatorError $error) { $value = null; } } throw $error; }
public function configure() { sfValidatorBase::setDefaultMessage('required', __('GENERAL_REQUIRED_FIELD_ERROR')); sfValidatorBase::setDefaultMessage('min_length', sprintf(__('GENERAL_FIELD_TOO_SHORT_ERROR'), '"%value%"', '%min_length%')); $this->setWidgets(array('email' => new sfWidgetFormInput(), 'return-url' => new sfWidgetFormInputHidden(), 'password' => new sfWidgetFormInputPassword(), 'rememberme' => new sfWidgetFormInputCheckbox(array()))); $this->setValidators(array('email' => new sfValidatorEmail(array('required' => true, 'max_length' => sfConfig::get('app_email_maxLength'), 'min_length' => sfConfig::get('app_email_minLength')), array('invalid' => __('WEBSITE_LOGIN_EMAIL_ERROR'))), 'password' => new sfValidatorString(array('max_length' => sfConfig::get('app_password_maxLength'), 'min_length' => sfConfig::get('app_password_minLength'))), 'rememberme' => new sfValidatorBoolean(array('required' => false)), 'return-url' => new sfValidatorString(array('required' => false)))); $this->widgetSchema->setLabels(array('email' => __('WEBSITE_LOGIN_EMAIL_LABEL'), 'password' => __('WEBSITE_LOGIN_PASSWORD_LABEL'), 'rememberme' => __('WEBSITE_LOGIN_REMEMBER_ME_LABEL'))); $this->widgetSchema->setNameFormat('login[%s]'); }
public function configure() { sfValidatorBase::setDefaultMessage('required', __('GENERAL_REQUIRED_FIELD_ERROR')); sfValidatorBase::setDefaultMessage('min_length', sprintf(__('GENERAL_FIELD_TOO_SHORT_ERROR'), '"%value%"', '%min_length%')); $this->setWidgets(array('username' => new sfWidgetFormInputText(), 'return-url' => new sfWidgetFormInputHidden())); $this->setValidators(array('username' => new sfValidatorString(array('required' => true, 'max_length' => sfConfig::get('app_username_maxLength'), 'min_length' => sfConfig::get('app_username_minLength'))), 'return-url' => new sfValidatorString(array('required' => false)))); $this->widgetSchema->setLabels(array('username' => __('WEBSITE_FORUM_USERNAME_USERNAME_LABEL'))); $this->widgetSchema->setNameFormat('chooseUsername[%s]'); }
/** * Configures the current validator. * * Available options: * * * from_time: The from time validator (required) * * to_time: The to time validator (required) * * from_field: The name of the "from" date field (optional, default: from) * * to_field: The name of the "to" date field (optional, default: to) * * @param array $options An array of options * @param array $messages An array of error messages * * @see sfValidatorBase */ protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->setMessage('invalid', 'From time should be before to time.'); $this->addRequiredOption('from_time'); $this->addRequiredOption('to_time'); $this->addOption('from_field', 'from'); $this->addOption('to_field', 'to'); }
public function configure() { sfValidatorBase::setDefaultMessage('required', __('GENERAL_REQUIRED_FIELD_ERROR')); sfValidatorBase::setDefaultMessage('min_length', sprintf(__('GENERAL_FIELD_TOO_SHORT_ERROR'), '"%value%"', '%min_length%')); $this->setWidgets(array('email' => new sfWidgetFormInput())); $this->setValidators(array('email' => new sfValidatorEmail(array('required' => true), array('invalid' => __('WEBSITE_FORGOTTEN_PSW_EMAIL_ERROR'))))); $this->widgetSchema->setLabels(array('email' => __('WEBSITE_FORGOTTEN_PSW_EMAIL_LABEL'))); $this->widgetSchema->setNameFormat('passwordForgotten[%s]'); }
public function setup() { sfConfig::set('linguagens', array('csharp' => 'C#', 'css' => 'CSS', 'gettext' => 'Gettext', 'groovy' => 'Groovy', 'haskell' => 'Haskell', 'html4strict' => 'HTML', 'java' => 'Java', 'java5' => 'Java 5', 'javascript' => 'JavaScript', 'jquery' => 'jQuery', 'mirc' => 'mIRC', 'mysql' => 'MySQL', 'objc' => 'Objective C', 'php' => 'PHP', 'plsql' => 'PL/SQL', 'properties' => 'Properties', 'python' => 'Python', 'rails' => 'Rails', 'ruby' => 'Ruby', 'scala' => 'Scala', 'sql' => 'SQL', 'text' => 'Texto puro', 'xml' => 'XML')); sfValidatorBase::setDefaultMessage('required', 'Campo obrigatório'); sfValidatorBase::setDefaultMessage('invalid', 'Campo inválido'); $this->enablePlugins('sfDoctrinePlugin'); $this->enablePlugins('sfGeshiPlugin'); $this->enablePlugins('sfDoctrineActAsTaggablePlugin'); }
public function configure() { sfValidatorBase::setDefaultMessage('required', __('GENERAL_REQUIRED_FIELD_ERROR')); sfValidatorBase::setDefaultMessage('min_length', sprintf(__('GENERAL_FIELD_TOO_SHORT_ERROR'), '"%value%"', '%min_length%')); $this->setWidgets(array('password1' => new sfWidgetFormInputPassword(), 'password2' => new sfWidgetFormInputPassword())); $this->setValidators(array('password1' => new sfValidatorString(array('max_length' => sfConfig::get('app_password_maxLength'), 'min_length' => sfConfig::get('app_password_minLength'))), 'password2' => new sfValidatorString(array('max_length' => sfConfig::get('app_password_maxLength'), 'min_length' => sfConfig::get('app_password_minLength'))))); $this->mergePostValidator(new sfValidatorSchemaCompare('password1', '==', 'password2', array(), array('invalid' => __('ACCOUNT_SETTINGS_PASSWORDS_DONT_MATCH_ERROR')))); $this->widgetSchema->setLabels(array('password1' => __('ACCOUNT_SETTINGS_PASSWORD'), 'password2' => __('ACCOUNT_SETTINGS_REPEAT_PASSWORD'))); $this->widgetSchema->setNameFormat('password[%s]'); }
protected function configure($options = array(), $messages = array()) { parent::configure($options, $messages); $this->addMessage('incorrect_format', 'Le format est incorrect.'); $this->addMessage('incorrect_year', 'L\'année est incorrecte.'); $this->addMessage('incorrect_month', 'Le mois est incorrect.'); $this->addMessage('incorrect_day', 'Le jour est incorrect.'); $this->addMessage('incorrect_time_hours', 'L\'heure est incorrecte.'); $this->addMessage('incorrect_time_minutes', 'Les minutes sont incorrectes.'); }
public function setup() { $this->enablePlugins('sfDoctrinePlugin'); //provisorio sfValidatorBase::setDefaultMessage('required', 'Campo obrigatório'); sfValidatorBase::setDefaultMessage('invalid', 'Campo inválido'); $this->enablePlugins('doAuthPlugin'); $this->enablePlugins('sfCKEditorPlugin'); $this->enablePlugins('sfFormExtraPlugin'); }
public function configure() { sfValidatorBase::setDefaultMessage('required', __('GENERAL_REQUIRED_FIELD_ERROR')); sfValidatorBase::setDefaultMessage('min_length', sprintf(__('GENERAL_FIELD_TOO_SHORT_ERROR'), '"%value%"', '%min_length%')); $this->setWidgets(array('email1' => new sfWidgetFormInputText(), 'email2' => new sfWidgetFormInputText())); $this->setValidators(array('email1' => new sfValidatorEmail(array('required' => true, 'max_length' => sfConfig::get('app_email_maxLength'), 'min_length' => sfConfig::get('app_email_minLength')), array('invalid' => __('ACCOUNT_SETTINGS_INVALID_EMAIL_ERROR'))), 'email2' => new sfValidatorEmail(array('required' => true, 'max_length' => sfConfig::get('app_email_maxLength'), 'min_length' => sfConfig::get('app_email_minLength')), array('invalid' => __('ACCOUNT_SETTINGS_INVALID_EMAIL_ERROR'))))); $this->mergePostValidator(new sfValidatorSchemaCompare('email1', '==', 'email2', array(), array('invalid' => __('ACCOUNT_SETTINGS_EMAILS_DONT_MATCH_ERROR')))); $this->widgetSchema->setLabels(array('email1' => __('ACCOUNT_SETTINGS_EMAIL'), 'email2' => __('ACCOUNT_SETTINGS_REPEAT_EMAIL'))); $this->widgetSchema->setNameFormat('email[%s]'); }
public function setup() { $this->setWebDir($this->getRootDir()); $this->enablePlugins('sfDoctrinePlugin'); $this->enablePlugins('tsUploadPlugin'); sfValidatorBase::setDefaultMessage('required', 'Не должно быть пустым'); sfValidatorBase::setDefaultMessage('invalid', 'Введите корректное значение'); $this->enablePlugins('sfJqueryReloadedPlugin'); $this->enablePlugins('sfAdminDashPlugin'); $this->enablePlugins('sfCKEditorPlugin'); }
public function configure() { sfValidatorBase::setDefaultMessage('required', __('GENERAL_REQUIRED_FIELD_ERROR')); sfValidatorBase::setDefaultMessage('min_length', sprintf(__('GENERAL_FIELD_TOO_SHORT_ERROR'), '"%value%"', '%min_length%')); $this->setWidgets(array('file' => new sfWidgetFormInputFile())); $this->widgetSchema->setNameFormat('avatar[%s]'); $this->setValidators(array('file' => new sfValidatorFile())); $validMimeTypes = array('image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif'); $this->validatorSchema['file']->setOption('mime_types', $validMimeTypes); $this->validatorSchema['file']->setOption('max_size', sfConfig::get('app_avatar_maxSize')); $messages = array('invalid' => 'Invalid file.', 'required' => 'Select a file to upload.', 'max_size' => 'The file can\'t be bigger than ' . sfConfig::get('app_avatar_maxSize') / 1000000 . 'MB', 'mime_types' => 'The file must be of JPEG, PNG , GIF format.'); $this->validatorSchema['file']->setMessages($messages); }
/** * Constructor. * * The first argument can be: * * * null * * an array of named sfValidatorBase instances * * @param mixed $fields Initial fields * @param array $options An array of options * @param array $messages An array of error messages * * @see sfValidatorBase */ public function __construct($fields = null, $options = array(), $messages = array()) { if (is_array($fields)) { foreach ($fields as $name => $validator) { $this[$name] = $validator; } } else { if (null !== $fields) { throw new InvalidArgumentException('sfValidatorSchema constructor takes an array of sfValidatorBase objects.'); } } parent::__construct($options, $messages); }
/** * Returns the arguments needed to format the message. * * @param bool $raw false to use it as arguments for the message format, true otherwise (default to false) * * @see getMessageFormat() */ public function getArguments($raw = false) { if ($raw) { return $this->arguments; } $arguments = array(); foreach ($this->arguments as $key => $value) { if (is_array($value)) { continue; } $arguments["%{$key}%"] = htmlspecialchars($value, ENT_QUOTES, sfValidatorBase::getCharset()); } return $arguments; }
public function configure() { sfValidatorBase::setDefaultMessage('required', __('GENERAL_REQUIRED_FIELD_ERROR')); sfValidatorBase::setDefaultMessage('min_length', sprintf(__('GENERAL_FIELD_TOO_SHORT_ERROR'), '"%value%"', '%min_length%')); $this->setWidgets(array('file' => new sfWidgetFormInputFile())); $this->widgetSchema->setNameFormat('import[%s]'); $this->setValidators(array('file' => new sfValidatorFile(array('required' => true)))); $validMimeTypes = array('application/xml'); $this->validatorSchema['file']->setOption('mime_types', $validMimeTypes); $this->validatorSchema['file']->setOption('max_size', 4000000); $messages = array('invalid' => 'Invalid file.', 'max_size' => 'The file can\'t be bigger than 4 MB', 'mime_types' => 'The file must be of XML format.'); $this->validatorSchema['file']->setMessages($messages); $this->widgetSchema->setLabels(array('file' => 'File:')); $this->widgetSchema->setNameFormat('import[%s]'); }
/** * Constructor. * * The first argument can be: * * * null * * a sfValidatorBase instance * * an array of sfValidatorBase instances * * @param mixed $validators Initial validators * @param array $options An array of options * @param array $messages An array of error messages * * @see sfValidatorBase */ public function __construct($validators = null, $options = array(), $messages = array()) { if ($validators instanceof sfValidatorBase) { $this->addValidator($validators); } else { if (is_array($validators)) { foreach ($validators as $validator) { $this->addValidator($validator); } } else { if (null !== $validators) { throw new InvalidArgumentException('sfValidatorOr constructor takes a sfValidatorBase object, or a sfValidatorBase array.'); } } } parent::__construct($options, $messages); }
/** * Constructor. * * The first argument can be: * * * null * * a sfValidatorBase instance * * an array of sfValidatorBase instances * * @param mixed $validators Initial validators * @param array $options An array of options * @param array $messages An array of error messages * * @see sfValidatorBase */ public function __construct($validators = null, $options = array(), $messages = array()) { if ($validators instanceof sfValidatorBase) { $this->addValidator($validators); } else { if (is_array($validators)) { foreach ($validators as $validator) { $this->addValidator($validator); } } else { if (!is_null($validators)) { throw new InvalidArgumentException('sfValidatorAnd constructor takes a sfValidatorBase object, or a sfValidatorBase array.'); } } } if (!isset($options['required'])) { $options['required'] = false; } parent::__construct($options, $messages); }
public function __construct($options = array(), $messages = array()) { $this->addRequiredOption(self::OPTION_WIDGET); parent::__construct($options, $messages); }
/** * Asks for a value and validates the response. * * Available options: * * * value: A value to try against the validator before asking the user * * attempts: Max number of times to ask before giving up (false by default, which means infinite) * * style: Style for question output (QUESTION by default) * * @param string|array $question * @param sfValidatorBase $validator * @param array $options * * @return mixed */ public function askAndValidate($question, sfValidatorBase $validator, array $options = array()) { if (!is_array($question)) { $question = array($question); } $options = array_merge(array('value' => null, 'attempts' => false, 'style' => 'QUESTION'), $options); // does the provided value passes the validator? if ($options['value']) { try { return $validator->clean($options['value']); } catch (sfValidatorError $error) { } } // no, ask the user for a valid user $error = null; while (false === $options['attempts'] || $options['attempts']--) { if (null !== $error) { $this->logBlock($error->getMessage(), 'ERROR'); } $value = $this->ask($question, $options['style'], null); try { return $validator->clean($value); } catch (sfValidatorError $error) { } } throw $error; }
/** * Returns true if the value is empty. * * @param mixed $value The input value * * @return bool true if the value is empty, false otherwise */ protected function isEmpty($value) { if (parent::isEmpty($value)) { return true; } if (is_array($value)) { $isEmpty = true; foreach ($value as $v) { if (!parent::isEmpty($v)) { $isEmpty = false; break; } } return $isEmpty; } return false; }
/** * @see sfValidatorBase */ protected function isEmpty($value) { if (is_array($value)) { // array is not empty when a value is found foreach ($value as $key => $val) { // int and string '0' are 'empty' values that are explicitly accepted if ($val === 0 || $val === '0' || !empty($val)) { return false; } } return true; } return parent::isEmpty($value); }
/** * @see sfProjectConfiguration */ public function initConfiguration() { $configCache = $this->getConfigCache(); // in debug mode, start global timer if ($this->isDebug() && !sfWebDebugPanelTimer::isStarted()) { sfWebDebugPanelTimer::startTime(); } // required core classes for the framework if (!sfConfig::get('sf_debug') && !sfConfig::get('sf_test') && !self::$coreLoaded) { $configCache->import('config/core_compile.yml', false); } $this->dispatcher->connect('autoload.filter_config', array($this, 'filterAutoloadConfig')); sfAutoload::getInstance()->register(); // load base settings include $configCache->checkConfig('config/settings.yml'); if ($file = $configCache->checkConfig('config/app.yml', true)) { include $file; } if (false !== sfConfig::get('sf_csrf_secret')) { sfForm::enableCSRFProtection(sfConfig::get('sf_csrf_secret')); } sfWidget::setCharset(sfConfig::get('sf_charset')); sfValidatorBase::setCharset(sfConfig::get('sf_charset')); // force setting default timezone if not set if ($default_timezone = sfConfig::get('sf_default_timezone')) { date_default_timezone_set($default_timezone); } else { if (sfConfig::get('sf_force_default_timezone', true)) { date_default_timezone_set(@date_default_timezone_get()); } } // error settings ini_set('display_errors', $this->isDebug() ? 'on' : 'off'); error_reporting(sfConfig::get('sf_error_reporting')); // initialize plugin configuration objects $this->initializePlugins(); // Disabled by default in symfony 1.1 because it causes problems with Doctrine. // If you want to enable it in your application, just copy the spl_autoload_register() line // in your configuration class. if (0 && $this->isDebug()) { spl_autoload_register(array(sfAutoload::getInstance(), 'autoloadAgain')); } // compress output if (!self::$coreLoaded) { ob_start(sfConfig::get('sf_compressed') ? 'ob_gzhandler' : ''); } self::$coreLoaded = true; }
/** * Sets the charset to use when validating strings. * * @param string $charset The charset */ public static function setCharset($charset) { self::$charset = $charset; }
protected function configure($options = array(), $messages = array()) { $this->options['required'] = false; parent::configure($options, $messages); $this->addRequiredOption('value_attribute_value'); }