public function init()
 {
     // валидаторы
     $alnum = new Zend_Validate_Alnum();
     $alnum->setMessage($this->messageAlnum);
     $notEmpty = new Zend_Validate_NotEmpty();
     $notEmpty->setMessage($this->notEmpty, "isEmpty");
     // создаем форму
     $this->setName('interview');
     $this->setAttribs(array('method' => "post", "class" => "form-horizontal"));
     $this->setDecorators(array('FormElements', 'Form'));
     $this->createFormElements($this, $this->elementsForm());
     return $this;
 }
Exemple #2
0
 public function init()
 {
     // валидаторы
     $alnum = new Zend_Validate_Alnum();
     $alnum->setMessage($this->messageAlnum);
     $notEmpty = new Zend_Validate_NotEmpty();
     $notEmpty->setMessage($this->notEmpty, "isEmpty");
     // фильтры
     $stringTrim = new Zend_Filter_StringTrim();
     $stripTags = new Zend_Filter_StripTags();
     // добавляем элементы формы в массив, потом будем собирать форму в цыкле
     $elementsForm = array('surname' => array('type' => 'text', 'label' => 'ФИО', 'attribs' => array('class' => 'span12', 'placeholder' => 'Фамилия')), 'name' => array('label' => 'Имя', 'attribs' => array('class' => 'span12', 'placeholder' => 'Имя')), 'patronymic' => array('label' => 'Отчество', 'attribs' => array('class' => 'span12', 'placeholder' => 'Отчество')), 'sex' => array('type' => 'select', 'label' => 'Пол', 'multiOptions' => array('male' => 'Мужской', 'female' => 'Женский')), 'birthday' => array('label' => 'Дата Рождения', 'attribs' => $this->datepicker), 'maidenName' => array('label' => 'Девичья фамилия (если менялась)'), 'placeOfBirth' => array('label' => 'Место рождения (по паспорту)'), 'oldCountry' => array('label' => 'Страна рождения', 'attribs' => array('class' => 'span12')), 'nationality' => array('label' => 'Текущее гражданство', 'attribs' => array('class' => 'span12')), 'citizenship' => array('label' => 'Гражданство (при рождении)', 'attribs' => array('class' => 'span12')), 'FIFather' => array('label' => 'И.Ф Отца', 'attribs' => array('class' => 'span12')), 'FIMother' => array('label' => 'И.Ф Матери', 'attribs' => array('class' => 'span12')), 'maritalStatus' => array('type' => 'select', 'label' => 'Семейное Положение', 'multiOptions' => array('married' => 'женат/замужем', 'single' => 'холост/незамужем')), 'addressOfRegistration' => array('label' => 'Адрес (по прописке)'), 'telephoneNumber' => array('label' => 'Номер телефона'), 'profession' => array('label' => 'Профессия'), 'refsCompany' => array('label' => 'Назв. фирмы'), 'cityWhereTriesFirm' => array('label' => 'Город, где находится фирма'), 'workPhone' => array('label' => 'Раб телефон'), 'firstBorderCrossing' => array('label' => 'Первый пункт пересечения границы'), 'foreignPassport' => array('type' => 'text', 'label' => 'Данные заграничного пасспорта', 'attribs' => array('class' => 'span12', 'placeholder' => 'Серия и номер')), 'startDate' => array('type' => 'text', 'label' => 'Дата выдачи', 'attribs' => array('class' => 'span12 datepicker', 'readonly' => '', 'placeholder' => 'Дата выдачи')), 'endDate' => array('type' => 'text', 'label' => 'Дата окончания', 'attribs' => array('class' => 'span12 datepicker', 'readonly' => '', 'placeholder' => 'Дата окончания')), 'issued' => array('type' => 'text', 'label' => 'Кем выдан', 'attribs' => array('class' => 'span12', 'placeholder' => 'Кем выдан')), 'schengenVisasLast' => array('type' => 'textarea', 'label' => 'Шенгенские визы за последние 3 года', 'attribs' => $this->textareaAttribs), 'serNumPassport' => array('label' => 'Серия, номер гражданского паспорта'), 'addressActual' => array('label' => 'Адрес (фактический)'), 'theseSpouse' => array('type' => 'textarea', 'label' => 'Данные супруга(и)Девичья фамилия, дата рождения, место рождения', 'attribs' => $this->textareaAttribs), 'forMinors' => array('type' => 'textarea', 'label' => 'Для несовершеннолетних: ФИО, адрес и гражданство законного представителя', 'attribs' => $this->textareaAttribs), 'whoPays' => array('type' => 'select', 'label' => 'Кто оплачивает поездку', 'multiOptions' => array('myself' => 'Сам турист', 'sponsor' => 'Спонсор')), 'sponsor' => array('label' => 'Кто является спонсором'));
     // создаем форму
     $this->setName('interview');
     $this->setAttribs(array('method' => "post", "class" => "form-horizontal"));
     $this->setDecorators(array('FormElements', 'Form'));
     $this->createFormElements($this, $elementsForm, $this->elementDecorators, $this->buttonLabel, $this->buttonDecorators);
     return $this;
 }
Exemple #3
0
 public function init()
 {
     $dbValidator = new Zend_Validate_Db_RecordExists(array('table' => 'users', 'field' => 'login'));
     $dbValidator->setMessage('Пользователя с таким именем нет в наших записях.');
     $alnum = new Zend_Validate_Alnum();
     $alnum->setMessage('Только буквы и цыфры!');
     $notEmpty = new Zend_Validate_NotEmpty();
     $notEmpty->setMessage('Поле обязательно для заполнения', 'isEmpty');
     $stringLength = new Zend_Validate_StringLength(array('min' => 3));
     $stringLength->setMessage('Длина поля должна быть больше трех символов.');
     if (!empty($_GET['referer'])) {
         $referer = $_GET['referer'];
     } else {
         $referer = '/';
     }
     $elementsForm = array('login' => array('type' => 'text', 'label' => 'Введите логин'), 'password' => array('type' => 'text', 'label' => 'Введите пароль', 'validators' => array('alnum' => $alnum, 'notEmpty' => $notEmpty, 'dbValidator' => $dbValidator, 'stringLength' => $stringLength)), 'redirect' => array('type' => 'hidden', 'attribs' => array('value' => $referer)));
     // имя формы;
     $this->setName('auth');
     $this->setAttribs(array('method' => "post", "role" => "form", "class" => "form-horizontal"));
     $this->createFormElements($this, $elementsForm, $this->elementDecorators, 'Войти', $this->buttonDecorators);
     return $this;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * returns an validator for a single category
  *
  * @return Zend_Filter_Input validator
  */
 protected function getValidator()
 {
     // define filter
     $filterTrim = new Zend_Filter_StringTrim();
     $filterUtf8 = new application_filter_utf8();
     $filter = array('id' => $filterTrim, 'name' => array($filterTrim, $filterUtf8), 'position' => $filterTrim);
     // define validators
     $validatorId = new application_validate_categoryid();
     $validatorId->setMessage(Zend_Registry::get('language')->translate("category doesn't exists"), application_validate_categoryid::NOT_EXISTS);
     $validatorNotEmpty = new Zend_Validate_NotEmpty();
     $validatorNotEmpty->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_NotEmpty::IS_EMPTY);
     $validatorAlnum = new Zend_Validate_Alnum(true);
     $validatorAlnum->setMessage(Zend_Registry::get('language')->translate('Only alphanummeric values allowed'), Zend_Validate_Alnum::NOT_ALNUM);
     $validatorAlnum->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_Alnum::STRING_EMPTY);
     $validatorNum = new Zend_Validate_Digits(false);
     $validatorNum->setMessage(Zend_Registry::get('language')->translate('Only digits allowed'), Zend_Validate_Digits::NOT_DIGITS);
     $validatorNum->setMessage(Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Validate_Digits::STRING_EMPTY);
     $validators = array('id' => array($validatorId, Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL), 'name' => array($validatorNotEmpty, Zend_Filter_Input::ALLOW_EMPTY => false, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_REQUIRED), 'position' => array($validatorNum, Zend_Filter_Input::PRESENCE => Zend_Filter_Input::PRESENCE_OPTIONAL));
     // create validation main object
     $validator = new Zend_Filter_Input($filter, $validators, array(), array(Zend_Filter_Input::NOT_EMPTY_MESSAGE => Zend_Registry::get('language')->translate("Value is required and can't be empty"), Zend_Filter_Input::BREAK_CHAIN => false));
     // return filter input object
     return $validator;
 }
Exemple #7
0
 /**
  * Функция создание формы 
  * @param type $objForm объект формы 
  * @param type $elementsForm элементы в  виде массива
  * @return type объект формы
  */
 protected function createFormElements($objForm, $elementsForm)
 {
     foreach ($elementsForm as $key => $value) {
         // определяем тип по умолчанию
         $type = !empty($value['type']) ? $value['type'] : 'text';
         // массив с опциями
         $params = array();
         if ($type !== 'hidden') {
             $params['label'] = !empty($value['label']) ? $value['label'] : die('Не оределлен атрибут label!');
         }
         $params['decorators'] = !empty($value['decorators']) ? $value['decorators'] : $this->elementDecorators();
         if (!empty($value['multiOptions'])) {
             $params['multiOptions'] = $value['multiOptions'];
         }
         $value['required'] = !empty($value['required']) ? $value['required'] : true;
         $value['attribs'] = !empty($value['attribs']) ? $value['attribs'] : array('class' => 'form-control');
         $value['filters'] = !empty($value['filters']) ? $value['filters'] : '';
         $value['validators'] = !empty($value['validators']) ? $value['validators'] : '';
         // присваевыем стандартные фильтры и валидаторы
         if (empty($value['filters'])) {
             $stringTrim = new Zend_Filter_StringTrim();
             $stripTags = new Zend_Filter_StripTags();
             $value['filters'] = array('stringTrim' => $stringTrim, 'stripTags' => $stripTags);
         }
         if (empty($value['validators'])) {
             $alnum = new Zend_Validate_Alnum();
             $alnum->setMessage('Только буквы и цыфры!');
             $notEmpty = new Zend_Validate_NotEmpty();
             $notEmpty->setMessage('Поле обязательно для заполнения', 'isEmpty');
             $value['validators'] = array('alnum' => $alnum, 'notEmpty' => $notEmpty);
         }
         // провеки на тип если нужен новый то надо добавить по аналогии
         switch ($type) {
             case 'text':
                 $elem = new Zend_Form_Element_Text($key);
                 break;
             case 'textarea':
                 $elem = new Zend_Form_Element_Textarea($key);
                 break;
             case 'select':
                 $elem = new Zend_Form_Element_Select($key);
                 break;
             case 'password':
                 $elem = new Zend_Form_Element_Password($key);
                 break;
             case 'hidden':
                 $elem = new Zend_Form_Element_Hidden($key);
                 break;
             case 'radio':
                 $elem = new Zend_Form_Element_Radio($key);
                 break;
         }
         // присваиваем атрибуты
         if (!empty($value['attribs'])) {
             foreach ($value['attribs'] as $k => $val) {
                 $params[$k] = $val;
             }
         }
         // присваиваем опции
         if (!empty($elem)) {
             $elem->setOptions($params);
         }
         // добавляем валидаторы
         if (!empty($value['validators']) && $type !== 'hidden') {
             foreach ($value['validators'] as $val) {
                 $elem->addValidator($val);
             }
         }
         // добавляем фильтры
         if (!empty($value['filters']) && $type !== 'hidden') {
             foreach ($value['filters'] as $val) {
                 $elem->addFilter($val);
             }
         }
         // вот тут писец
         if (!empty($value['required']) && $type !== 'hidden') {
             $elem->setRequired(TRUE);
         }
         // добавляем элемент на форму
         $objForm->addElement($elem);
     }
     // добавляем кнопку
     $objForm->addElement('submit', 'submit', array('label' => $this->buttonLabel, 'decorators' => $this->buttonDecorators(), 'class' => 'btn btn-default'));
     return $objForm;
 }
 /**
  * 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;
 }
Exemple #9
0
 protected function _createAlnumValidator($errorMessage)
 {
     $alnumValidator = new Zend_Validate_Alnum();
     $alnumValidator->setMessage($errorMessage, Zend_Validate_Alnum::NOT_ALNUM);
     return $alnumValidator;
 }