示例#1
0
 /**
  * Testing setMessage
  */
 public function testSetSingleMessage()
 {
     $messages = $this->_validator->getMessageTemplates();
     $this->assertNotEquals('TestMessage', $messages[Zend_Validate_EmailAddress::INVALID]);
     $this->_validator->setMessage('TestMessage');
     $messages = $this->_validator->getMessageTemplates();
     $this->assertEquals('TestMessage', $messages[Zend_Validate_EmailAddress::INVALID]);
 }
示例#2
0
 public function __construct($options = null)
 {
     parent::__construct($options);
     $translate = Zend_Registry::get('Zend_Translate');
     $language = $translate->getLocale();
     $baseurl = Zend_Controller_Front::getInstance()->getBaseUrl();
     $actionUrl = $baseurl . '/' . $language . '/account/fetchpassword';
     $this->setName('fetchpassword_form');
     $this->setAction($actionUrl);
     $this->addElementPrefixPath('Oibs_Decorators', 'Oibs/Decorators/', 'decorator');
     $mailvalid = new Zend_Validate_EmailAddress();
     $mailvalid->setMessage('email-invalid', Zend_Validate_EmailAddress::INVALID);
     $mailvalid->setMessage('email-invalid-hostname', Zend_Validate_EmailAddress::INVALID_HOSTNAME);
     $mailvalid->setMessage('email-invalid-mx-record', Zend_Validate_EmailAddress::INVALID_MX_RECORD);
     $mailvalid->setMessage('email-dot-atom', Zend_Validate_EmailAddress::DOT_ATOM);
     $mailvalid->setMessage('email-quoted-string', Zend_Validate_EmailAddress::QUOTED_STRING);
     $mailvalid->setMessage('email-invalid-local-part', Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
     $mailvalid->setMessage('email-length-exceeded', Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
     $mailvalid->hostnameValidator->setMessage('hostname-invalid-hostname', Zend_Validate_Hostname::INVALID_HOSTNAME);
     $mailvalid->hostnameValidator->setMessage('hostname-local-name-not-allowed', Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
     $mailvalid->hostnameValidator->setMessage('hostname-unknown-tld', Zend_Validate_Hostname::UNKNOWN_TLD);
     $mailvalid->hostnameValidator->setMessage('hostname-invalid-local-name', Zend_Validate_Hostname::INVALID_LOCAL_NAME);
     $mailvalid->hostnameValidator->setMessage('hostname-undecipherable-tld', Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
     // Username input form element
     $username = new Zend_Form_Element_Text('email');
     $username->setLabel($translate->_("account-fetchpassword-email"))->removeDecorator('DtDdWrapper')->addFilter('StringtoLower')->setRequired(true)->addValidators(array($mailvalid))->setDecorators(array('FetchPasswordDecorator'));
     $hidden = new Zend_Form_Element_Hidden('submittedform');
     $hidden->setValue('fetchpassword');
     // Form submit buttom element
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel($translate->_("account-fetchpassword-submit"))->removeDecorator('DtDdWrapper')->setAttrib('class', 'fetchpassword-submit left');
     // Add elements to form
     $this->addElements(array($username, $submit, $hidden));
 }
示例#3
0
 /**
  * Konfiguriert das Formularelement.
  */
 public function init()
 {
     parent::init();
     $this->setAttrib('placeholder', $this->getTranslator()->translate('email_format'));
     $this->setAttrib('size', 60);
     $validator = new Zend_Validate_EmailAddress();
     $validator->setMessage('admin_validate_error_email');
     $this->addValidator($validator);
 }
 public function init()
 {
     parent::init();
     $this->setAction(WEB_ROOT . '/commenting/comment/add');
     $this->setAttrib('id', 'comment-form');
     $user = current_user();
     /************************************************************
      *REVISIONS
      * Ver        Date       Author          Description
      * --------  ----------  --------------  ----------------------
      * 1.0       09/02/2015  mrs175          1. added validators/form limitations for author name, email, and comment
      ************************************************************/
     //Validators
     //------------------------------------------------------------------
     $notEmptyValidator = array('validator' => 'NotEmpty', 'breakChainOnFailure' => true, 'options' => array('messages' => array(Zend_Validate_NotEmpty::IS_EMPTY => __('Please fill in this box.'), Zend_Validate_NotEmpty::INVALID => __('Please only use letters numbers and punctuation.'))));
     $alphaNumericValidator = array('validator' => 'Regex', 'breakChainOnFailure' => true, 'options' => array('pattern' => '#^[a-zA-Z0-9.*@+!\\-_%\\#\\^&$ ]*$#u', 'messages' => array(Zend_Validate_Regex::INVALID => __('Please only use these special characters for your name: + ! @ # $ % ^ & * . - _'), Zend_Validate_Regex::ERROROUS => __('Please only use these special characters for your name: + ! @ # $ % ^ & * . - _'), Zend_Validate_Regex::NOT_MATCH => __('Please only use these special characters for your name: + ! @ # $ % ^ & * . - _'))));
     //form element options
     //----------------------------------------------------------
     $nameOptions = array('label' => __('Name (required)'), 'required' => true, 'size' => '25', 'maxlength' => '25', 'validators' => array($notEmptyValidator, $alphaNumericValidator));
     $emailOptions = array('label' => __('Email (required)'), 'required' => true, 'size' => '100', 'maxlength' => '70', 'validators' => array($notEmptyValidator));
     $commentOptions = array('label' => __('1500 character limit'), 'id' => 'comment-form-body', 'rows' => "8", 'cols' => "50", 'maxlength' => '1500', 'required' => true, 'filters' => array(array('StripTags', array('allowTags' => array('p', 'span', 'em', 'strong', 'a', 'ul', 'ol', 'li'), 'allowAttribs' => array('style', 'href')))), 'validators' => array($notEmptyValidator));
     //Adding Elements to the form
     //-------------------------------------------------------------------------------
     //auto-filling the email and name boxes for logged in users
     //then making them read only, so logged in users must use their registered name and email
     if ($user) {
         $emailOptions['value'] = $user->email;
         $emailOptions['readonly'] = true;
         $emailOptions['onfocus'] = "this.blur()";
         $nameOptions['value'] = $user->name;
         $nameOptions['readonly'] = true;
         $nameOptions['onfocus'] = "this.blur()";
     }
     $this->addElement('text', 'author_name', $nameOptions);
     $this->addElement('text', 'author_email', $emailOptions);
     $this->addElement('textarea', 'body', $commentOptions);
     $emailValidator = new Zend_Validate_EmailAddress();
     $emailValidator->setMessage('Please enter an email address like stuff@email.com');
     $this->getElement('author_email')->addValidator($emailValidator, true, array());
     if (get_option('recaptcha_public_key') && get_option('recaptcha_private_key')) {
         $this->addElement('captcha', 'captcha', array('label' => __("Please verify you're a human"), 'captcha' => array('captcha' => 'ReCaptcha', 'pubkey' => get_option('recaptcha_public_key'), 'privkey' => get_option('recaptcha_private_key'), 'ssl' => true)));
         $this->getElement('captcha')->removeDecorator('ViewHelper');
     }
     $request = Zend_Controller_Front::getInstance()->getRequest();
     $params = $request->getParams();
     $record_id = $this->_getRecordId($params);
     $record_type = $this->_getRecordType($params);
     $this->addElement('hidden', 'record_id', array('value' => $record_id, 'decorators' => array('ViewHelper')));
     $this->addElement('hidden', 'path', array('value' => $request->getPathInfo(), 'decorators' => array('ViewHelper')));
     if (isset($params['module'])) {
         $this->addElement('hidden', 'module', array('value' => $params['module'], 'decorators' => array('ViewHelper')));
     }
     $this->addElement('hidden', 'record_type', array('value' => $record_type, 'decorators' => array('ViewHelper')));
     fire_plugin_hook('commenting_form', array('comment_form' => $this));
     $this->addElement('submit', 'submit', array('label' => __('Submit')));
 }
 public function __construct()
 {
     // Validators --------------------------
     $notEmpty = new Zend_Validate_NotEmpty(array(true));
     $notEmpty->setMessage($this->_errorMessages['isEmpy']);
     $digits = new Zend_Validate_Digits();
     $digits->setMessage($this->_errorMessages['digits']);
     $emailValidator = new Zend_Validate_EmailAddress();
     $emailValidator->setMessage($this->_errorMessages['emailValidator']);
     $foneValidator = new Zend_Validate_StringLength();
     $foneValidator->setMin(8);
     $foneValidator->setMessage($this->_errorMessages['foneValidator']);
     //--------------------------------------
     $nome = new Zend_Form_Element_Text('nome');
     $nome->setAttrib('class', 'form-control');
     $nome->setRequired(true);
     $nome->addValidator($notEmpty, true);
     //--------------------------------------------------------
     $fone = new Zend_Form_Element_Text('fone');
     $fone->setAttrib('class', 'form-control');
     $fone->setRequired(true);
     $fone->addValidator($notEmpty, true);
     $fone->addValidator($digits, true);
     $fone->addValidator($foneValidator, true);
     //--------------------------------------------------------
     $email = new Zend_Form_Element_Text('email');
     $email->setAttrib('class', 'form-control');
     $email->setRequired(true);
     $email->addValidator($notEmpty, true);
     $email->addValidator($emailValidator, true);
     //--------------------------------------------------------
     $mensagem = new Zend_Form_Element_Textarea('mensagem');
     $mensagem->setAttrib('class', 'form-control');
     $mensagem->setAttrib('cols', 30);
     $mensagem->setAttrib('rows', 10);
     $mensagem->setRequired(true);
     $mensagem->addValidator($notEmpty, true);
     //--------------------------------------------------------
     $this->addElement($nome);
     $this->addElement($fone);
     $this->addElement($email);
     $this->addElement($mensagem);
     $this->setElementDecorators(array('ViewHelper', 'Errors'));
 }
示例#6
0
 public function __construct($options = null)
 {
     parent::__construct($options);
     $translate = Zend_Registry::get('Zend_Translate');
     $this->removeDecorator('DtDdWrapper');
     $this->setName('register_form');
     $this->setAttrib('id', 'register_form');
     $this->addElementPrefixPath('Oibs_Decorators', 'Oibs/Decorators/', 'decorator');
     $this->addElementPrefixPath('Oibs_Validators', 'OIBS/Validators/', 'validate');
     $city = new Zend_Form_Element_Text('city');
     $city->setLabel($translate->_("account-register-city"))->setRequired(true)->addValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'field-empty'))), array('Regex', true, array('/^[\\p{L}0-9.\\- ]*$/'))))->setDecorators(array('RegistrationDecorator'));
     $mailvalid = new Zend_Validate_EmailAddress();
     $mailvalid->setMessage('email-invalid', Zend_Validate_EmailAddress::INVALID);
     $mailvalid->setMessage('email-invalid-hostname', Zend_Validate_EmailAddress::INVALID_HOSTNAME);
     $mailvalid->setMessage('email-invalid-mx-record', Zend_Validate_EmailAddress::INVALID_MX_RECORD);
     $mailvalid->setMessage('email-dot-atom', Zend_Validate_EmailAddress::DOT_ATOM);
     $mailvalid->setMessage('email-quoted-string', Zend_Validate_EmailAddress::QUOTED_STRING);
     $mailvalid->setMessage('email-invalid-local-part', Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
     $mailvalid->setMessage('email-length-exceeded', Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
     $mailvalid->hostnameValidator->setMessage('hostname-invalid-hostname', Zend_Validate_Hostname::INVALID_HOSTNAME);
     $mailvalid->hostnameValidator->setMessage('hostname-local-name-not-allowed', Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
     $mailvalid->hostnameValidator->setMessage('hostname-unknown-tld', Zend_Validate_Hostname::UNKNOWN_TLD);
     $mailvalid->hostnameValidator->setMessage('hostname-invalid-local-name', Zend_Validate_Hostname::INVALID_LOCAL_NAME);
     $mailvalid->hostnameValidator->setMessage('hostname-undecipherable-tld', Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
     $email = new Zend_Form_Element_Text('email');
     $email->setLabel($translate->_("account-register-email"))->setRequired(true)->addFilter('StringtoLower')->addValidators(array($mailvalid))->addErrorMessage('email-invalid')->setDecorators(array('RegistrationDecorator'));
     $e_options = array("" => "account-select", "private_sector" => "account-register_private_sector", "public_sector" => "account-register_public_sector", "education_sector" => "account-register_education_sector", "student" => "account-register_student", "pentioner" => "account-register_pentioner", "other" => "account-register_other");
     $employment = new Zend_Form_Element_Select('employment');
     $employment->setLabel($translate->_("account-register-employment"))->setRequired(true)->addValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'field-empty')))))->addMultiOptions($e_options)->setDecorators(array('RegistrationDecorator'));
     $username = new Zend_Form_Element_Text('username');
     $username->setLabel($translate->_("account-register-username"))->setRequired(true)->addValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'field-empty'))), array('StringLength', false, array(4, 16, 'messages' => array('stringLengthTooShort' => 'field-too-short', 'stringLengthTooLong' => 'field-too-long'))), new Oibs_Validators_UsernameExists('username'), new Oibs_Validators_Username('username')))->setDecorators(array('RegistrationDecorator'));
     $password = new Zend_Form_Element_Password('password');
     $password->setLabel($translate->_("account-register-password"));
     $password->setRequired(true);
     $password->addValidators(array(new Oibs_Validators_RepeatValidator('confirm_password'), array('NotEmpty', true, array('messages' => array('isEmpty' => 'field-empty'))), array('StringLength', false, array(4, 16, 'messages' => array('stringLengthTooShort' => 'field-too-short', 'stringLengthTooLong' => 'field-too-long')))));
     $password->setDecorators(array('RegistrationDecorator'));
     $confirm_password = new Zend_Form_Element_Password('confirm_password');
     $confirm_password->setLabel($translate->_("account-register-password_confirm"));
     $confirm_password->setRequired(true);
     $confirm_password->addValidator('NotEmpty', true, array('messages' => array('isEmpty' => 'field-empty')));
     $confirm_password->addValidator('StringLength', false, array(4, 16, 'messages' => array('stringLengthTooShort' => 'field-too-short', 'stringLengthTooLong' => 'field-too-long')));
     $confirm_password->setDecorators(array('RegistrationDecorator'));
     $captcha = new Zend_Form_Element('captcha');
     $captcha->setDecorators(array('CaptchaDecorator'));
     $captcha_text = new Zend_Form_Element_Text('captcha_text');
     $captcha_text->setLabel($translate->_("account-register-enter_text"))->addValidators(array(new Oibs_Validators_CaptchaValidator(), array('NotEmpty', true, array('messages' => array('isEmpty' => 'field-empty')))))->setRequired(true)->setDecorators(array('RegistrationDecorator'));
     $text = sprintf($translate->_("account-register-terms_and_privacy"), "terms", "privacy");
     // this solution sucks. the codes are in the translate block directly.
     // anyone think of a fix to move codes out of there?
     // - Joel
     $terms = new Zend_Form_Element_Checkbox('terms');
     $terms->setDescription($text)->setLabel("account-register-terms")->setChecked(false)->setRequired(true)->addValidators(array(new Oibs_Validators_CheckboxValidator()))->setDecorators(array('RegistrationTermsDecorator'));
     // checkboxes always have a value of 1or0, this is a "feature" in ZF
     // custom validator is a workaround
     // -Joel
     $submit = new Zend_Form_Element_Submit('submit');
     $submit->setLabel($translate->_("account-register-submit"))->removeDecorator('DtDdWrapper')->setDecorators(array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'class' => 'registration_submit_div'))))->setAttrib('class', 'registration_form_submit_' . $translate->getLocale());
     $this->addElements(array($username, $password, $confirm_password, $city, $email, $employment, $captcha, $captcha_text, $terms, $submit));
     /*$this->addDisplayGroup(array('username', 'password', 'confirm_password'), 'account_information');
       $this->account_information->setLegend('register-account-information');
       $this->account_information->removeDecorator('DtDdWrapper');
       $this->addDisplayGroup(array('city', 'email', 'employment'), 'personal_information');
       $this->personal_information->removeDecorator('DtDdWrapper');
       $this->personal_information->setLegend('register-personal-information');
       
       $this->addDisplayGroup(array('captcha', 'captcha_text', 'terms', 'submit'), 'confirmations');
       $this->confirmations->removeDecorator('DtDdWrapper');
       $this->confirmations->setLegend('register-confirmations');*/
 }
示例#7
0
 /**
  * Add validation rules for particular fields
  *
  * @return \Zend_Validate_Interface
  */
 protected function _getValidationRulesBeforeSave()
 {
     $userNameNotEmpty = new \Zend_Validate_NotEmpty();
     $userNameNotEmpty->setMessage(__('User Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY);
     $firstNameNotEmpty = new \Zend_Validate_NotEmpty();
     $firstNameNotEmpty->setMessage(__('First Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY);
     $lastNameNotEmpty = new \Zend_Validate_NotEmpty();
     $lastNameNotEmpty->setMessage(__('Last Name is a required field.'), \Zend_Validate_NotEmpty::IS_EMPTY);
     $emailValidity = new \Zend_Validate_EmailAddress();
     $emailValidity->setMessage(__('Please enter a valid email.'), \Zend_Validate_EmailAddress::INVALID);
     /** @var $validator \Magento\Framework\Validator\Object */
     $validator = $this->_validatorObject->create();
     $validator->addRule($userNameNotEmpty, 'username')->addRule($firstNameNotEmpty, 'firstname')->addRule($lastNameNotEmpty, 'lastname')->addRule($emailValidity, 'email');
     if ($this->_willSavePassword()) {
         $this->_addPasswordValidation($validator);
     }
     return $validator;
 }
示例#8
0
文件: Base.php 项目: rukzuk/rukzuk
 /**
  * @param  string $email
  * @param  string  $field
  * @return boolean
  */
 protected function validateEmail($email, $field = 'email')
 {
     $emailValidator = new EmailValidator(array('hostname' => new \Zend_Validate_Hostname(array('tld' => false))));
     $emailValidator->setMessage('Ungültiger Typ. String erwartet', EmailValidator::INVALID);
     $emailValidator->setMessage("'%value%' ist keine gültige Email nach dem Format name@hostname", EmailValidator::INVALID_FORMAT);
     $emailValidator->setMessage("'%hostname%' ist kein gültiger Hostname für die Email '%value%'", EmailValidator::INVALID_HOSTNAME);
     $emailValidator->setMessage("'%value%' ist länger als die zulässige Länge", EmailValidator::LENGTH_EXCEEDED);
     if (!$emailValidator->isValid($email)) {
         $messages = array_values($emailValidator->getMessages());
         $this->addError(new Error($field, $email, $messages));
         return false;
     }
     return true;
 }
 public function step2Action()
 {
     $this->reloadConfig();
     configureTheme(APPLICATION_THEME, 'install');
     $session = new Zend_Session_Namespace('Install');
     // Set up Doctrine DB
     require_once APPLICATION_DIRECTORY . '/Joobsbox/Db/Doctrine.php';
     $loader = Zend_Loader_Autoloader::getInstance();
     $loader->pushAutoloader(array('Doctrine', 'autoload'));
     $doctrineConfig = new Zend_Config_Xml(APPLICATION_DIRECTORY . "/config/db.xml", "doctrine");
     $manager = Doctrine_Manager::getInstance();
     $manager->setAttribute(Doctrine::ATTR_TBLNAME_FORMAT, $this->config->db->prefix . '%s');
     $manager->setCollate('utf8_unicode_ci');
     $manager->setCharset('utf8');
     $manager->openConnection($doctrineConfig->connection_string);
     Doctrine::createTablesFromModels($doctrineConfig->models_path);
     $db = Zend_Registry::get("db");
     $db->delete($this->config->db->prefix . "categories", array("Name='Uncategorized'"));
     $db->insert($this->config->db->prefix . "categories", array('ID' => 0, 'Name' => 'Uncategorized', 'Link' => 'Uncategorized', 'OrderIndex' => 100, 'Parent' => 0));
     // Make the form
     $this->adminForm = new Zend_Form();
     $this->adminForm->setAction($this->view->baseUrl . "/install/step2")->setMethod('post')->setLegend('Administrator credentials');
     $notEmpty = new Zend_Validate_NotEmpty();
     $realname = $this->adminForm->createElement('text', 'realname')->setLabel('Your name:')->addFilter('StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[required]')->addValidator($notEmpty->setMessage($this->view->translate("Real name is mandatory")))->setRequired(true);
     $notEmpty = clone $notEmpty;
     $username = $this->adminForm->createElement('text', 'username')->setLabel('Username:'******'StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[required]')->addValidator($notEmpty->setMessage($this->view->translate("Username is mandatory")))->setRequired(true);
     $notEmpty = clone $notEmpty;
     $password = $this->adminForm->createElement('text', 'password')->setLabel('Password:'******'StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[required]')->addValidator($notEmpty->setMessage($this->view->translate("Password is mandatory")))->setRequired(true);
     $notEmpty = clone $notEmpty;
     $emailValidator = new Zend_Validate_EmailAddress();
     $email = $this->adminForm->createElement('text', 'email')->setLabel('Email:')->addFilter('StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[email,required]')->addValidator($notEmpty->setMessage($this->view->translate("Email is mandatory")))->addValidator($emailValidator->setMessage($this->view->translate("Email is invalid")))->setRequired(true);
     $submit = $this->adminForm->createElement('submit', 'Save')->setLabel('Save');
     $this->adminForm->addElement($realname)->addElement($username)->addElement($password)->addElement($email)->addElement($submit);
     $dg = $this->adminForm->addDisplayGroup(array('realname', 'username', 'password', 'email', 'Save'), 'user');
     if ($this->getRequest()->isPost()) {
         $this->validateAdminUser();
         return;
     }
     $this->view->form = $this->adminForm->render();
 }
示例#10
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = Mage::helper('customer')->__($this->getAttribute()->getStoreLabel());
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 /**
                 $this->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
                 $this->__("Invalid type given. String expected")
                 $this->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
                 $this->__("'%value%' does not match the expected structure for a DNS hostname")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
                 $this->__("'%value%' does not appear to be a valid local network name")
                 $this->__("'%value%' does not appear to be a valid URI hostname")
                 $this->__("'%value%' appears to be an IP address, but IP addresses are not allowed")
                 $this->__("'%value%' appears to be a local network name but local network names are not allowed")
                 $this->__("'%value%' appears to be a DNS hostname but cannot extract TLD part")
                 $this->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
                 */
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be an IP address, but IP addresses are not allowed"), Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list"), Zend_Validate_Hostname::UNKNOWN_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position"), Zend_Validate_Hostname::INVALID_DASH);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'"), Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot extract TLD part"), Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' does not appear to be a valid local network name"), Zend_Validate_Hostname::INVALID_LOCAL_NAME);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a local network name but local network names are not allowed"), Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
                 $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded"), Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $validator = new Zend_Validate_Date(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
         }
     }
     return true;
 }
示例#11
0
文件: Form.php 项目: rizkioa/etak6
 protected function _createEmailEmailAddressValidator($errorMessage)
 {
     $emailValidator = new Zend_Validate_EmailAddress();
     $emailValidator->setMessage($errorMessage, Zend_Validate_EmailAddress::INVALID_FORMAT);
     return $emailValidator;
 }
 protected function _validateEmail($value = null)
 {
     if ($value) {
         $validator = new Zend_Validate_EmailAddress();
         $validator->setMessage(Mage::helper('eav')->__('"%s" invalid type entered.', $value), Zend_Validate_EmailAddress::INVALID);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid email address.', $value), Zend_Validate_EmailAddress::INVALID_FORMAT);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid hostname.', $value), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid hostname.', $value), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid hostname.', $value), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid email address.', $value), Zend_Validate_EmailAddress::DOT_ATOM);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid email address.', $value), Zend_Validate_EmailAddress::QUOTED_STRING);
         $validator->setMessage(Mage::helper('eav')->__('"%s" is not a valid email address.', $value), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
         $validator->setMessage(Mage::helper('eav')->__('"%s" exceeds the allowed length.', $value), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be an IP address, but IP addresses are not allowed"), Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match TLD against known list"), Zend_Validate_Hostname::UNKNOWN_TLD);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but contains a dash in an invalid position"), Zend_Validate_Hostname::INVALID_DASH);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'"), Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but cannot extract TLD part"), Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' does not appear to be a valid local network name"), Zend_Validate_Hostname::INVALID_LOCAL_NAME);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a local network name but local network names are not allowed"), Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
         $validator->setMessage(Mage::helper('customer')->__("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded"), Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
         if (!$validator->isValid($value)) {
             return array_unique($validator->getMessages());
         }
     }
     return;
 }
 public function step2Action()
 {
     $this->reloadConfig();
     configureTheme(APPLICATION_THEME, 'install');
     $session = new Zend_Session_Namespace('Install');
     // Create tables
     $xmlSchema = ezcDbSchema::createFromFile('xml', APPLICATION_DIRECTORY . '/data/schema.xml');
     $schema =& $xmlSchema->getSchema();
     if ($this->config->db->prefix != "") {
         $keys = array_keys($schema);
         foreach ($keys as $tableName) {
             $schema[$this->config->db->prefix . $tableName] = clone $schema[$tableName];
             unset($schema[$tableName]);
         }
     }
     $dbconfig = new Zend_Config_Xml(DB_CONFIG_LOCATION, 'zend_db');
     $db = ezcDbFactory::create($dbconfig->connection_string);
     $xmlSchema->writeToDb($db);
     $db = Zend_Registry::get("db");
     $db->delete($this->config->db->prefix . $this->config->dbtables->categories, array("name='General'"));
     $db->insert($this->config->db->prefix . $this->config->dbtables->categories, array('id' => 0, 'name' => 'General', 'link' => 'general', 'orderindex' => 100, 'parent' => 0));
     // Make the form
     $this->adminForm = new Zend_Form();
     $this->adminForm->setAction($this->view->baseUrl . "/install/step2")->setMethod('post')->setLegend('Administrator credentials');
     $notEmpty = new Zend_Validate_NotEmpty();
     $realname = $this->adminForm->createElement('text', 'realname')->setLabel('Your name:')->addFilter('StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[required]')->addValidator($notEmpty->setMessage($this->view->translate("Real name is mandatory")))->setRequired(true);
     $notEmpty = clone $notEmpty;
     $username = $this->adminForm->createElement('text', 'username')->setLabel('Username:'******'StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[required]')->addValidator($notEmpty->setMessage($this->view->translate("Username is mandatory")))->setRequired(true);
     $notEmpty = clone $notEmpty;
     $password = $this->adminForm->createElement('text', 'password')->setLabel('Password:'******'StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[required]')->addValidator($notEmpty->setMessage($this->view->translate("Password is mandatory")))->setRequired(true);
     $notEmpty = clone $notEmpty;
     $emailValidator = new Zend_Validate_EmailAddress();
     $email = $this->adminForm->createElement('text', 'email')->setLabel('Email:')->addFilter('StripTags')->addFilter('StringTrim')->addFilter('HtmlEntities')->setAttrib('class', 'validate[email,required]')->addValidator($notEmpty->setMessage($this->view->translate("Email is mandatory")))->addValidator($emailValidator->setMessage($this->view->translate("Email is invalid")))->setRequired(true);
     $submit = $this->adminForm->createElement('submit', 'save')->setLabel('Save');
     $this->adminForm->addElement($realname)->addElement($username)->addElement($password)->addElement($email)->addElement($submit);
     $dg = $this->adminForm->addDisplayGroup(array('realname', 'username', 'password', 'email', 'save'), 'user');
     if ($this->getRequest()->isPost()) {
         $this->validateAdminUser();
         return;
     }
     $this->view->form = $this->adminForm->render();
 }
 public static function overrideEmailAddressValidator()
 {
     $validator = new Zend_Validate_EmailAddress();
     $validator->setMessage(_("'%value%' is no valid email address in the basic format local-part@hostname"), Zend_Validate_EmailAddress::INVALID_FORMAT);
     return $validator;
 }
示例#15
0
 public function init()
 {
     $this->setMethod('post');
     $this->setEnctype('multipart/form-data');
     $this->setName('edit_profile_form');
     $this->setAttrib('id', 'edit-profile-form');
     $this->addElementPrefixPath('Oibs_Form_Decorator', 'Oibs/Form/Decorator/', 'decorator');
     $mailvalid = new Zend_Validate_EmailAddress();
     $mailvalid->setMessage('email-invalid', Zend_Validate_EmailAddress::INVALID);
     $mailvalid->setMessage('email-invalid-hostname', Zend_Validate_EmailAddress::INVALID_HOSTNAME);
     $mailvalid->setMessage('email-invalid-mx-record', Zend_Validate_EmailAddress::INVALID_MX_RECORD);
     $mailvalid->setMessage('email-dot-atom', Zend_Validate_EmailAddress::DOT_ATOM);
     $mailvalid->setMessage('email-quoted-string', Zend_Validate_EmailAddress::QUOTED_STRING);
     $mailvalid->setMessage('email-invalid-local-part', Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
     $mailvalid->setMessage('email-length-exceeded', Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
     $mailvalid->hostnameValidator->setMessage('hostname-invalid-hostname', Zend_Validate_Hostname::INVALID_HOSTNAME);
     $mailvalid->hostnameValidator->setMessage('hostname-local-name-not-allowed', Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
     $mailvalid->hostnameValidator->setMessage('hostname-unknown-tld', Zend_Validate_Hostname::UNKNOWN_TLD);
     $mailvalid->hostnameValidator->setMessage('hostname-invalid-local-name', Zend_Validate_Hostname::INVALID_LOCAL_NAME);
     $mailvalid->hostnameValidator->setMessage('hostname-undecipherable-tld', Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
     // Clear div
     $clear = '<div class="clear"></div>';
     // Headers
     $accountInformation = new Oibs_Form_Element_Note('accountinformation');
     $accountInformation->setValue($clear . '<h3>Account information</h3>' . $clear);
     $personalInformation = new Oibs_Form_Element_Note('personalinformation');
     $personalInformation->setValue('<h3>Personal Information</h3>' . $clear);
     $locationInformation = new Oibs_Form_Element_Note('locationinformation');
     $locationInformation->setValue('<h3>Location Information</h3>' . $clear);
     $employmentInformation = new Oibs_Form_Element_Note('employmentinformation');
     $employmentInformation->setValue('<h3>Employment Information</h3>' . $clear);
     $subscribeInformation = new Oibs_Form_Element_Note('subscribeinformation');
     $subscribeInformation->setValue('<h3>Subscribe settings</h3>' . $clear);
     // Public text
     $publictext = 'Public';
     // Username for description
     $auth = Zend_Auth::getInstance();
     $identity = $auth->getIdentity();
     $usernametext = $identity->username;
     $username = new Zend_Form_Element_Hidden('username');
     $username->setLabel('Username')->setDescription($usernametext);
     $usernamepublic = new Zend_Form_Element_Hidden('username_publicity');
     $usernamepublic->setLabel($publictext);
     $openid = new Zend_Form_Element_Text('openid');
     $openid->setLabel('Open-ID')->setAttrib('id', 'open-ID')->addValidators(array(new Oibs_Validators_OpenidExists()));
     $openidclear = new Oibs_Form_Element_Note('openidclear');
     $openidclear->setValue($clear);
     $password = new Zend_Form_Element_Password('password');
     $password->setLabel('New password')->setAttrib('id', 'password')->addValidators(array(new Oibs_Validators_RepeatValidator('confirm_password'), array('NotEmpty', true, array('messages' => array('isEmpty' => 'Empty'))), array('StringLength', false, array(4, 22, 'messages' => array('stringLengthTooShort' => 'Password too short (4-22 characters)', 'stringLengthTooLong' => 'Password too long (4-22 characters)')))));
     $passwordclear = new Oibs_Form_Element_Note('passwordclear');
     $passwordclear->setValue($clear);
     $confirmpassword = new Zend_Form_Element_Password('confirm_password');
     $confirmpassword->setLabel('Confirm password')->setAttrib('id', 'confirm-password')->addValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Empty'))), array('StringLength', false, array(4, 22, 'messages' => array('stringLengthTooShort' => 'Password too short (4-22 characters)', 'stringLengthTooLong' => 'Password too long (4-22 characters)')))));
     $confirmpasswordclear = new Oibs_Form_Element_Note('confirm_passwordclear');
     $confirmpasswordclear->setValue($clear);
     $email = new Zend_Form_Element_Text('email');
     $email->setLabel('Email')->setAttrib('id', 'email')->setRequired(true)->addFilter('StringtoLower')->addValidators(array($mailvalid, array('NotEmpty', true, array('messages' => array('isEmpty' => 'Email empty'))), array('StringLength', false, array(6, 50, 'messages' => array('stringLengthTooShort' => 'Email too short (6-50 characters)', 'stringLengthTooLong' => 'Email too long (6-50 characters)')))));
     $emailclear = new Oibs_Form_Element_Note('emailclear');
     $emailclear->setValue($clear);
     $gravatar = new Zend_Form_Element_Hidden('gravatartext');
     $gravatar->setLabel('Gravatar')->setDescription('<div style="text-align: right;">Enable <a href="http://www.gravatar.com">gravatar</a></div>');
     $gravatarcheck = new Zend_Form_Element_Checkbox('gravatar');
     $phone = new Zend_Form_Element_Text('phone');
     $phone->setLabel('Phone')->setAttrib('id', 'phone');
     $phonepublic = new Zend_Form_Element_Checkbox('phone_publicity');
     $phonepublic->setLabel($publictext);
     $firstname = new Zend_Form_Element_Text('firstname');
     $firstname->setLabel('First name')->setAttrib('id', 'first-name');
     $firstnamepublic = new Zend_Form_Element_Checkbox('firstname_publicity');
     $firstnamepublic->setLabel($publictext);
     // DB: surname
     $lastname = new Zend_Form_Element_Text('surname');
     $lastname->setLabel('Last name')->setAttrib('id', 'last-name');
     $lastnamepublic = new Zend_Form_Element_Checkbox('surname_publicity');
     $lastnamepublic->setLabel($publictext);
     $gender = new Zend_Form_Element_Select('gender');
     $gender->setLabel('Gender')->setAttrib('id', 'gender')->addMultiOptions(array('Select', 'Male', 'Female'));
     $genderpublic = new Zend_Form_Element_Checkbox('gender_publicity');
     $genderpublic->setLabel($publictext);
     $birthday = new Zend_Form_Element_Text('birthday');
     $birthday->setLabel('Date of Birth')->setAttrib('id', 'birthday')->setValidators(array(new Zend_Validate_Date('birthday')));
     $birthdaypublic = new Zend_Form_Element_Checkbox('birthday_publicity');
     $birthdaypublic->setLabel($publictext);
     $biography = new Zend_Form_Element_Textarea('biography');
     $biography->setLabel('Biography')->setAttrib('id', 'biography')->setAttrib('rows', 30)->setAttrib('cols', 45)->addValidators(array(array('StringLength', false, array(0, 4000, 'messages' => array('stringLengthTooLong' => 'Biography too long')))));
     //->setDescription('<div id="progressbar_biography" class="progress_ok"></div>');
     $biographypublic = new Zend_Form_Element_Checkbox('biography_publicity');
     $biographypublic->setLabel($publictext);
     $intereststext = new Oibs_Form_Element_Note('intereststext');
     $intereststext->setValue('<div class="input-column1"></div>' . '<div class="input-column2 help">(Use commas to separate tags)</div><div class="clear"></div>');
     $interests = new Zend_Form_Element_Text('interests');
     $interests->setLabel('My interest (tags)')->setAttrib('id', 'interests');
     $interestsclear = new Oibs_Form_Element_Note('interestsclear');
     $interestsclear->setValue($clear);
     $weblinks_websites = new Oibs_Form_Element_Note('weblinks_websites');
     $weblinks_websites->setValue('<div class="input-column-website1"><label><strong>Links to my websites:</strong></label></div>');
     $weblinks_name = new Oibs_Form_Element_Note('weblinks_name');
     $weblinks_name->setValue('<div class="input-column-website2">Name</div>');
     $weblinks_url = new Oibs_Form_Element_Note('weblinks_url');
     $weblinks_url->setValue('<div class="input-column-website3">Url</div><div class="clear"></div>');
     $nameTooLongText = 'Name too long (max 45)';
     $urlTooLongText = 'URL too long (max 150)';
     $weblinks_name_site1 = new Zend_Form_Element_Text('weblinks_name_site1');
     $weblinks_name_site1->setLabel('Web site 1')->setAttrib('id', 'website1-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText)))));
     $weblinks_url_site1 = new Zend_Form_Element_Text('weblinks_url_site1');
     $weblinks_url_site1->setAttrib('id', 'website1-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText)))));
     $weblinks_name_site2 = new Zend_Form_Element_Text('weblinks_name_site2');
     $weblinks_name_site2->setLabel('Web site 2')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText)))));
     $weblinks_url_site2 = new Zend_Form_Element_Text('weblinks_url_site2');
     $weblinks_url_site2->setAttrib('id', 'website2-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText)))));
     $weblinks_name_site3 = new Zend_Form_Element_Text('weblinks_name_site3');
     $weblinks_name_site3->setLabel('Web site 3')->setAttrib('id', 'website3-name')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText)))));
     $weblinks_url_site3 = new Zend_Form_Element_Text('weblinks_url_site3');
     $weblinks_url_site3->setAttrib('id', 'website3-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText)))));
     $weblinks_name_site4 = new Zend_Form_Element_Text('weblinks_name_site4');
     $weblinks_name_site4->setLabel('Web site 4')->setAttrib('id', 'website4-name')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText)))));
     $weblinks_url_site4 = new Zend_Form_Element_Text('weblinks_url_site4');
     $weblinks_url_site4->setAttrib('id', 'website4-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText)))));
     $weblinks_name_site5 = new Zend_Form_Element_Text('weblinks_name_site5');
     $weblinks_name_site5->setLabel('Web site 5')->setAttrib('id', 'website5-name')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'messages' => array('stringLengthTooLong' => $nameTooLongText)))));
     $weblinks_url_site5 = new Zend_Form_Element_Text('weblinks_url_site5');
     $weblinks_url_site5->setAttrib('id', 'website5-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText)))));
     $languages = new Default_Model_Languages();
     $allLanguages = $languages->getAllNamesAndIds();
     $userlanguage = new Zend_Form_Element_Select('userlanguage');
     $userlanguage->setLabel('User interface language')->setAttrib('id', 'user-interface-language')->addMultiOption('', 'Select');
     foreach ($allLanguages as $language) {
         $userlanguage->addMultiOption($language['id_lng'], $language['name_lng']);
     }
     $userlanguageclear = new Oibs_Form_Element_Note('userlanguageclear');
     $userlanguageclear->setValue($clear);
     /*
             $avatar = new Zend_Form_Element_File('avatar');
             $avatar->setLabel('Avatar image');
     */
     // DB: city
     $hometown = new Zend_Form_Element_Text('city');
     $hometown->setLabel('Hometown')->setAttrib('id', 'hometown')->setRequired(true)->addValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'Hometown empty'))), array('Regex', true, array('/^[\\p{L}0-9.\\- ]*$/'))));
     $hometownpublic = new Zend_Form_Element_Checkbox('city_publicity');
     $hometownpublic->setLabel($publictext);
     $hometownpublic->helper = 'FormHidden';
     $address = new Zend_Form_Element_Text('address');
     $address->setLabel('Address')->setAttrib('id', 'address');
     $addresspublic = new Zend_Form_Element_Checkbox('address_publicity');
     $addresspublic->setLabel($publictext)->setAttrib('checked', 'checked')->setValue(1);
     $addresspublic->helper = 'FormHidden';
     $country_model = new Default_Model_Countries();
     $allCountries = $country_model->getAllCountries();
     $usercountry = new Zend_Form_Element_Select('country');
     $usercountry->setLabel('Country of Residence')->setAttrib('id', 'country')->addMultiOption('', 'Select');
     foreach ($allCountries as $country) {
         $usercountry->addMultiOption($country['iso_ctr'], $country['printable_name_ctr']);
     }
     $usercountrypublic = new Zend_Form_Element_Checkbox('country_publicity');
     $usercountrypublic->setLabel($publictext);
     $timezone_model = new Default_Model_Timezones();
     $allTimezones = $timezone_model->getAllTimezones();
     $usertimezone = new Zend_Form_Element_Select('usertimezone');
     $usertimezone->setLabel('Time Zone')->setAttrib('id', 'time-zone')->addMultiOption('', 'Select');
     foreach ($allTimezones as $timezone) {
         $usertimezone->addMultiOption($timezone['id_tmz'], $timezone['gmt_tmz'] . ' ' . $timezone['timezone_location_tmz']);
     }
     $usertimezonepublic = new Zend_Form_Element_Checkbox('usertimezone_publicity');
     $usertimezonepublic->setLabel($publictext);
     $userProfilesModel = new Default_Model_UserProfiles();
     $employments = $userProfilesModel->getEmployments();
     $employments = array_merge(array('' => 'Select'), $employments);
     $employment = new Zend_Form_Element_Select('employment');
     $employment->setLabel('I am currently')->setAttrib('id', 'status')->setRequired(true)->addMultiOptions($employments)->setErrorMessages(array('Select status'));
     $employmentpublic = new Zend_Form_Element_Checkbox('employment_publicity');
     $employmentpublic->setLabel($publictext);
     // DB: company
     $employer_organization = new Zend_Form_Element_Text('company');
     $employer_organization->setLabel('Employer / Organization')->setAttrib('id', 'employer-organization');
     $employer_organizationpublic = new Zend_Form_Element_Checkbox('company_publicity');
     $employer_organizationpublic->setLabel($publictext);
     //Subscribe things
     $favouritesModel = new Default_Model_UserHasFavourites();
     $subscribeOptions = $favouritesModel->getFollows();
     unset($subscribeOptions['8']);
     //Unsetting the translation box till its in use.
     //print_r($subscribeOptions);die;
     $test = new Zend_Form_Element_MultiCheckbox('lol');
     //$test->setV
     $subscribeClasses = array("own_follows" => "Own contents", "fvr_follows" => "Favourite contents");
     foreach ($subscribeClasses as $key => $value) {
         $subscribe[$key] = new Zend_Form_Element_MultiCheckbox($key);
         $subscribe[$key]->setLabel('Activities you want to follow in your ' . $value);
         $subscribe[$key]->addMultiOptions($subscribeOptions);
     }
     $subscribeclear = new Oibs_Form_Element_Note('subscribeclear');
     $subscribeclear->setValue($clear);
     $save = new Zend_Form_Element_Submit('save');
     $save->setLabel('Save profile')->setAttrib('id', 'save-profile')->setAttrib('class', 'submit-button');
     $cancel = new Zend_Form_Element_Submit('cancel');
     $cancel->setLabel('Cancel')->setAttrib('id', 'cancel')->setAttrib('class', 'submit-button');
     $this->addElements(array($accountInformation, $username, $usernamepublic, $openid, $openidclear, $password, $passwordclear, $confirmpassword, $confirmpasswordclear, $personalInformation, $email, $emailclear, $gravatar, $gravatarcheck, $phone, $phonepublic, $firstname, $firstnamepublic, $lastname, $lastnamepublic, $gender, $genderpublic, $birthday, $birthdaypublic, $biography, $biographypublic, $weblinks_websites, $weblinks_name, $weblinks_url, $weblinks_name_site1, $weblinks_url_site1, $weblinks_name_site2, $weblinks_url_site2, $weblinks_name_site3, $weblinks_url_site3, $weblinks_name_site4, $weblinks_url_site4, $weblinks_name_site5, $weblinks_url_site5, $userlanguage, $userlanguageclear, $locationInformation, $hometown, $hometownpublic, $address, $addresspublic, $usercountry, $usercountrypublic, $usertimezone, $usertimezonepublic, $employmentInformation, $employment, $employmentpublic, $employer_organization, $employer_organizationpublic, $save, $cancel));
     $accountInformation->setDecorators(array('ViewHelper'));
     $personalInformation->setDecorators(array('ViewHelper'));
     $locationInformation->setDecorators(array('ViewHelper'));
     $employmentInformation->setDecorators(array('ViewHelper'));
     $subscribeInformation->setDecorators(array('ViewHelper'));
     $username->setDecorators(array('InputDecorator'));
     $usernamepublic->setDecorators(array('PublicDecorator'));
     $openid->setDecorators(array('InputDecorator'));
     $openidclear->setDecorators(array('ViewHelper'));
     $password->setDecorators(array('InputDecorator'));
     $passwordclear->setDecorators(array('ViewHelper'));
     $confirmpassword->setDecorators(array('InputDecorator'));
     $confirmpasswordclear->setDecorators(array('ViewHelper'));
     $email->setDecorators(array('InputDecorator'));
     $emailclear->setDecorators(array('ViewHelper'));
     $gravatar->setDecorators(array('InputDecorator'));
     $gravatarcheck->setDecorators(array('PublicDecorator'));
     $phone->setDecorators(array('InputDecorator'));
     $phonepublic->setDecorators(array('PublicDecorator'));
     $firstname->setDecorators(array('InputDecorator'));
     $firstnamepublic->setDecorators(array('PublicDecorator'));
     $lastname->setDecorators(array('InputDecorator'));
     $lastnamepublic->setDecorators(array('PublicDecorator'));
     $gender->setDecorators(array('InputDecorator'));
     $genderpublic->setDecorators(array('PublicDecorator'));
     $birthday->setDecorators(array('InputDecorator'));
     $birthdaypublic->setDecorators(array('PublicDecorator'));
     $biography->setDecorators(array('InputDecorator'));
     $biographypublic->setDecorators(array('PublicDecorator'));
     $intereststext->setDecorators(array('ViewHelper'));
     $interests->setDecorators(array('InputDecorator'));
     $interestsclear->setDecorators(array('ViewHelper'));
     $weblinks_websites->setDecorators(array('ViewHelper'));
     $weblinks_name->setDecorators(array('ViewHelper'));
     $weblinks_url->setDecorators(array('ViewHelper'));
     $weblinks_name_site1->setDecorators(array('InputWebsiteNameDecorator'));
     $weblinks_url_site1->setDecorators(array('InputWebsiteUrlDecorator'));
     $weblinks_name_site2->setDecorators(array('InputWebsiteNameDecorator'));
     $weblinks_url_site2->setDecorators(array('InputWebsiteUrlDecorator'));
     $weblinks_name_site3->setDecorators(array('InputWebsiteNameDecorator'));
     $weblinks_url_site3->setDecorators(array('InputWebsiteUrlDecorator'));
     $weblinks_name_site4->setDecorators(array('InputWebsiteNameDecorator'));
     $weblinks_url_site4->setDecorators(array('InputWebsiteUrlDecorator'));
     $weblinks_name_site5->setDecorators(array('InputWebsiteNameDecorator'));
     $weblinks_url_site5->setDecorators(array('InputWebsiteUrlDecorator'));
     $userlanguage->setDecorators(array('InputDecorator'));
     $userlanguageclear->setDecorators(array('ViewHelper'));
     $hometown->setDecorators(array('InputDecorator'));
     $hometownpublic->setDecorators(array('PublicDecorator'));
     $address->setDecorators(array('InputDecorator'));
     $addresspublic->setDecorators(array('PublicDecorator'));
     $usercountry->setDecorators(array('InputDecorator'));
     $usercountrypublic->setDecorators(array('PublicDecorator'));
     $usertimezone->setDecorators(array('InputDecorator'));
     $usertimezonepublic->setDecorators(array('PublicDecorator'));
     $employment->setDecorators(array('InputDecorator'));
     $employmentpublic->setDecorators(array('PublicDecorator'));
     $employer_organization->setDecorators(array('InputDecorator'));
     $employer_organizationpublic->setDecorators(array('PublicDecorator'));
     $subscribe['own_follows']->setDecorators(array('InputDecorator'));
     $subscribe['fvr_follows']->setDecorators(array('InputDecorator'));
     $subscribeclear->setDecorators(array('ViewHelper'));
     $save->setDecorators(array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'openOnly' => true, 'id' => 'save_changes'))));
     $cancel->setDecorators(array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'closeOnly' => true))));
     $this->setDecorators(array('FormElements', 'Form'));
 }
示例#16
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return string
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = $this->getAttribute()->getStoreLabel();
     $validateRules = $this->getAttribute()->getValidateRules();
     if (!empty($validateRules['input_validation'])) {
         switch ($validateRules['input_validation']) {
             case 'alphanumeric':
                 $validator = new Zend_Validate_Alnum(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic and digit characters.', $label), Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new Zend_Validate_Digits();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Digits::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" contains not only digit characters.', $label), Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new Zend_Validate_Alpha(true);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" has not only alphabetic characters.', $label), Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is an empty string.', $label), Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 $validator = new Zend_Validate_EmailAddress();
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 $validator = new Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return array(Mage::helper('customer')->__('"%s" is not a valid URL.', $label));
                 }
                 break;
             case 'date':
                 $format = Mage::app()->getLocale()->getDateFormat(Varien_Date::DATE_INTERNAL_FORMAT);
                 $validator = new Zend_Validate_Date($format);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" invalid type entered.', $label), Zend_Validate_Date::INVALID);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" is not a valid date.', $label), Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(Mage::helper('customer')->__('"%s" does not fit the entered date format.', $label), Zend_Validate_Date::FALSEFORMAT);
                 break;
         }
     }
     return true;
 }
 /**
  * Validate email
  *
  * @param string $value
  * @return string
  */
 protected function _validateEmail($value)
 {
     $label = Mage::helper('enterprise_rma')->getContactEmailLabel();
     $validator = new Zend_Validate_EmailAddress();
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" invalid type entered.', $label), Zend_Validate_EmailAddress::INVALID);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_FORMAT);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_HOSTNAME);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid hostname.', $label), Zend_Validate_EmailAddress::INVALID_MX_RECORD);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::DOT_ATOM);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::QUOTED_STRING);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" is not a valid email address.', $label), Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
     $validator->setMessage(Mage::helper('enterprise_rma')->__('"%s" exceeds the allowed length.', $label), Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
     if (!$validator->isValid($value)) {
         return array_unique($validator->getMessages());
     }
     return true;
 }
 public function __construct($arrParam = array(), $options = null)
 {
     $validateNotEmpty = new Zend_Validate_NotEmpty();
     $validateNotEmpty->setMessage('Không được để trống.');
     //////////////////////////////////
     //Kiem tra fullname /////////////
     //////////////////////////////////
     $validateStrLength = new Zend_Validate_StringLength(3, 100);
     $validateStrLength->setMessage('Giá trị nhập vào không hợp lệ, giá trị nhập vào là một chuỗi.', 'stringLengthInvalid');
     $validateStrLength->setMessage("Chuỗi nhập vào phải lớn hơn %min% ký tự.", 'stringLengthTooShort');
     $validateStrLength->setMessage("Chuỗi nhập vào phải nhỏ hơn %max% ký tự.", 'stringLengthTooLong');
     $validator = new Zend_Validate();
     $validator->addValidator($validateNotEmpty, true)->addValidator($validateStrLength, true);
     if (!$validator->isValid($arrParam['fullname'])) {
         $message = $validator->getMessages();
         $this->_messageError['fullname'] = 'Họ và tên: ' . current($message);
         $arrParam['fullname'] = '';
     }
     //////////////////////////////////
     //Kiem tra email /////////////
     //////////////////////////////////
     $validateEmail = new Zend_Validate_EmailAddress();
     $validateEmail->setMessage('Không hợp lệ, Giá trị nhập vào nên là chuỗi.', 'emailAddressInvalid');
     $validateEmail->setMessage("'%value%' không đúng định dạng email.Email có dạng 'local-part@hostname'", 'emailAddressInvalidFormat');
     $validateEmail->setMessage("'%value%' không đúng định dạng email.Email có dạng 'local-part@hostname'", 'emailAddressInvalidHostname');
     $validator = new Zend_Validate();
     $validator->addValidator($validateNotEmpty, true)->addValidator($validateEmail, true);
     if (!$validator->isValid($arrParam['email'])) {
         $message = $validator->getMessages();
         $this->_messageError['email'] = 'Địa chỉ Email: ' . current($message);
         $arrParam['email'] = '';
     }
     //////////////////////////////////
     //Kiem tra title /////////////
     //////////////////////////////////
     $validator = new Zend_Validate();
     $validator->addValidator($validateNotEmpty, true)->addValidator($validateStrLength, true);
     if (!$validator->isValid($arrParam['title'])) {
         $message = $validator->getMessages();
         $this->_messageError['title'] = 'Tiêu đề ' . current($message);
         $arrParam['title'] = '';
     }
     //////////////////////////////////
     //Kiem tra Content /////////////
     //////////////////////////////////
     $validateStrLengthMsg = new Zend_Validate_StringLength(20);
     $validateStrLengthMsg->setMessage('Giá trị nhập vào không hợp lệ, giá trị nhập vào là một chuỗi.', 'stringLengthInvalid');
     $validateStrLengthMsg->setMessage("Chuỗi nhập vào phải lớn hơn %min% ký tự.", 'stringLengthTooShort');
     $validateStrLengthMsg->setMessage("Chuỗi nhập vào phải nhỏ hơn %max% ký tự.", 'stringLengthTooLong');
     $validator = new Zend_Validate();
     $validator->addValidator($validateNotEmpty, true)->addValidator($validateStrLengthMsg, true);
     if (!$validator->isValid($arrParam['message'])) {
         $message = $validator->getMessages();
         $this->_messageError['message'] = 'Nội dung: ' . current($message);
         $arrParam['message'] = '';
     }
     //========================================
     // TRUYEN CAC GIA TRI DUNG VAO MANG $_arrData
     //========================================
     $this->_arrData = $arrParam;
 }
示例#19
0
 /**
  * Validate value by attribute input validation rule
  *
  * @param string $value
  * @return array|true
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function _validateInputRule($value)
 {
     // skip validate empty value
     if (empty($value)) {
         return true;
     }
     $label = $this->getAttribute()->getStoreLabel();
     $validateRules = $this->getAttribute()->getValidationRules();
     $inputValidation = ArrayObjectSearch::getArrayElementByName($validateRules, 'input_validation');
     if (!is_null($inputValidation)) {
         switch ($inputValidation) {
             case 'alphanumeric':
                 $validator = new \Zend_Validate_Alnum(true);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alnum::INVALID);
                 $validator->setMessage(__('"%1" contains non-alphabetic or non-numeric characters.', $label), \Zend_Validate_Alnum::NOT_ALNUM);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alnum::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'numeric':
                 $validator = new \Zend_Validate_Digits();
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Digits::INVALID);
                 $validator->setMessage(__('"%1" contains non-numeric characters.', $label), \Zend_Validate_Digits::NOT_DIGITS);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Digits::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'alpha':
                 $validator = new \Zend_Validate_Alpha(true);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Alpha::INVALID);
                 $validator->setMessage(__('"%1" contains non-alphabetic characters.', $label), \Zend_Validate_Alpha::NOT_ALPHA);
                 $validator->setMessage(__('"%1" is an empty string.', $label), \Zend_Validate_Alpha::STRING_EMPTY);
                 if (!$validator->isValid($value)) {
                     return $validator->getMessages();
                 }
                 break;
             case 'email':
                 /**
                 __("'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded")
                 __("Invalid type given. String expected")
                 __("'%value%' appears to be a DNS hostname but contains a dash in an invalid position")
                 __("'%value%' does not match the expected structure for a DNS hostname")
                 __("'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'")
                 __("'%value%' does not appear to be a valid local network name")
                 __("'%value%' does not appear to be a valid URI hostname")
                 __("'%value%' appears to be an IP address, but IP addresses are not allowed")
                 __("'%value%' appears to be a local network name but local network names are not allowed")
                 __("'%value%' appears to be a DNS hostname but cannot extract TLD part")
                 __("'%value%' appears to be a DNS hostname but cannot match TLD against known list")
                 */
                 $validator = new \Zend_Validate_EmailAddress();
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_EmailAddress::INVALID);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_FORMAT);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_HOSTNAME);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(__('"%1" is not a valid hostname.', $label), \Zend_Validate_EmailAddress::INVALID_MX_RECORD);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::DOT_ATOM);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::QUOTED_STRING);
                 $validator->setMessage(__('"%1" is not a valid email address.', $label), \Zend_Validate_EmailAddress::INVALID_LOCAL_PART);
                 $validator->setMessage(__('"%1" uses too many characters.', $label), \Zend_Validate_EmailAddress::LENGTH_EXCEEDED);
                 $validator->setMessage(__("'%value%' looks like an IP address, which is not an acceptable format."), \Zend_Validate_Hostname::IP_ADDRESS_NOT_ALLOWED);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match the TLD against known list."), \Zend_Validate_Hostname::UNKNOWN_TLD);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but contains a dash in an invalid position."), \Zend_Validate_Hostname::INVALID_DASH);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but we cannot match it against the hostname schema for TLD '%tld%'."), \Zend_Validate_Hostname::INVALID_HOSTNAME_SCHEMA);
                 $validator->setMessage(__("'%value%' looks like a DNS hostname but cannot extract TLD part."), \Zend_Validate_Hostname::UNDECIPHERABLE_TLD);
                 $validator->setMessage(__("'%value%' does not look like a valid local network name."), \Zend_Validate_Hostname::INVALID_LOCAL_NAME);
                 $validator->setMessage(__("'%value%' looks like a local network name, which is not an acceptable format."), \Zend_Validate_Hostname::LOCAL_NAME_NOT_ALLOWED);
                 $validator->setMessage(__("'%value%' appears to be a DNS hostname, but the given punycode notation cannot be decoded."), \Zend_Validate_Hostname::CANNOT_DECODE_PUNYCODE);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
             case 'url':
                 $parsedUrl = parse_url($value);
                 if ($parsedUrl === false || empty($parsedUrl['scheme']) || empty($parsedUrl['host'])) {
                     return [__('"%1" is not a valid URL.', $label)];
                 }
                 $validator = new \Zend_Validate_Hostname();
                 if (!$validator->isValid($parsedUrl['host'])) {
                     return [__('"%1" is not a valid URL.', $label)];
                 }
                 break;
             case 'date':
                 $validator = new \Zend_Validate_Date(\Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT);
                 $validator->setMessage(__('"%1" invalid type entered.', $label), \Zend_Validate_Date::INVALID);
                 $validator->setMessage(__('"%1" is not a valid date.', $label), \Zend_Validate_Date::INVALID_DATE);
                 $validator->setMessage(__('"%1" does not fit the entered date format.', $label), \Zend_Validate_Date::FALSEFORMAT);
                 if (!$validator->isValid($value)) {
                     return array_unique($validator->getMessages());
                 }
                 break;
         }
     }
     return true;
 }
示例#20
0
 public function __construct()
 {
     // Validators --------------------------
     $notEmpty = new Zend_Validate_NotEmpty(array(true));
     $notEmpty->setMessage($this->_errorMessages['isEmpy']);
     $digits = new Zend_Validate_Digits();
     $digits->setMessage($this->_errorMessages['digits']);
     $emailValidator = new Zend_Validate_EmailAddress();
     $emailValidator->setMessage($this->_errorMessages['emailValidator']);
     $foneValidator = new Zend_Validate_StringLength();
     $foneValidator->setMin(8);
     $foneValidator->setMessage($this->_errorMessages['foneValidator']);
     $dddValidator = new Zend_Validate_StringLength();
     $dddValidator->setMin(2);
     $dddValidator->setMessage($this->_errorMessages['foneValidator']);
     //--------------------------------------
     $nome = new Zend_Form_Element_Text('nome');
     $nome->setAttrib('class', 'form-control');
     $nome->setAttrib('required', true);
     $nome->setAttrib('accesskey', 'n');
     $nome->setRequired(true);
     $nome->addValidator($notEmpty, true);
     //--------------------------------------------------------
     $fone = new Zend_Form_Element_Text('fone');
     $fone->setAttrib('class', 'form-control fone-input');
     $fone->setAttrib('required', true);
     $fone->setAttrib('accesskey', 'f');
     $fone->setRequired(true);
     $fone->addValidator($notEmpty, true);
     $fone->addValidator($digits, true);
     $fone->addValidator($foneValidator, true);
     //--------------------------------------------------------
     $cidade = new Zend_Form_Element_Text('cidade');
     $cidade->setAttrib('class', 'form-control');
     $cidade->setAttrib('required', false);
     $cidade->setAttrib('accesskey', 'c');
     $cidade->setRequired(false);
     //--------------------------------------------------------
     $ddd = new Zend_Form_Element_Text('ddd');
     $ddd->setAttrib('class', 'form-control');
     $ddd->setAttrib('required', true);
     $ddd->setAttrib('accesskey', 'd');
     $ddd->setRequired(true);
     $ddd->addValidator($notEmpty, true);
     $ddd->addValidator($digits, true);
     $ddd->addValidator($dddValidator, true);
     //--------------------------------------------------------
     $email = new Zend_Form_Element_Text('email');
     $email->setAttrib('class', 'form-control');
     $email->setAttrib('required', true);
     $email->setAttrib('accesskey', 'e');
     $email->setRequired(true);
     $email->addValidator($notEmpty, true);
     $email->addValidator($emailValidator, true);
     //--------------------------------------------------------
     $mensagem = new Zend_Form_Element_Textarea('mensagem');
     $mensagem->setAttrib('class', 'form-control');
     $mensagem->setAttrib('required', true);
     $mensagem->setAttrib('accesskey', 'm');
     $mensagem->setAttrib('cols', 1);
     $mensagem->setAttrib('rows', 1);
     $mensagem->setRequired(true);
     $mensagem->addValidator($notEmpty, true);
     //--------------------------------------------------------
     $imovel = new Zend_Form_Element_Text('imovel');
     $imovel->setAttrib('class', 'form-control');
     $imovel->setAttrib('accesskey', 'i');
     $imovel->setAttrib('cols', 1);
     $imovel->setAttrib('rows', 1);
     $imovel->setRequired(false);
     //--------------------------------------------------
     $this->addElement($nome);
     $this->addElement($fone);
     $this->addElement($ddd);
     $this->addElement($email);
     $this->addElement($cidade);
     $this->addElement($mensagem);
     $this->addElement($imovel);
     $this->setElementDecorators(array('ViewHelper', 'Errors'));
 }