Пример #1
0
 public function buildFilter()
 {
     //category char 16 not null,
     $category = new Input('category');
     $category->setAllowEmpty(TRUE);
     $category->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags')->attachByName('StringToLower');
     $category->getValidatorChain()->attachByName('inArray', array('haystack' => $this->categories));
     //title varchar 128 not null
     $title = new Input('title');
     $title->setAllowEmpty(TRUE);
     $title->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags');
     $titleRegex = new Regex(array('pattern' => '/^[a-zA-Z0-9 ]*$/'));
     $titleRegex->setMessage('Title should contain only numbers, letters or spaces.');
     $title->getValidatorChain()->attach($titleRegex)->attachByName('StringLength', array('min' => 1, 'max' => 128));
     //date_created timestamp not null default current_timestamp
     $dateCreated = new Input('dateCreated');
     $dateCreated->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags');
     $dateCreated->getValidatorChain()->attachByName('StringLength', array('min' => 10, 'max' => 10));
     // 	    date_expires timestamp not null default null
     // 	    descripton varchar 4096 default null
     // 	    photo_filename varchar 1024 default null
     // 	    contact_name varchar 255 default null
     // 	    contact_email varchar 255 default null
     // 	    contact_phone varchar 32 default null
     // 	    city varchar 128 default null
     // 	    country char 2 not null
     // 	    price decimal 12,2 not null
     // 	    delete_code char 16 character set utf8 collate utf8_bin default null
     $this->add($category)->add($title)->add($dateCreated);
 }
Пример #2
0
 /**
  * @return RegexValidator
  */
 public function getValidator()
 {
     if (null === $this->validator) {
         $validator = new RegexValidator('/' . self::CURRENCY_FORMAT . '/');
         $validator->setMessage('Must be in US currency including dollar sign', RegexValidator::NOT_MATCH);
         $this->validator = $validator;
     }
     return $this->validator;
 }
Пример #3
0
 /**
  * Get a validator if none has been set.
  * @return ValidatorInterface
  */
 public function getValidator()
 {
     if (null === $this->validator) {
         $validator = new RegexValidator('/^([0-9\\(\\)\\/\\+ \\-]*)$/');
         $validator->setMessage('Please use digits only', RegexValidator::NOT_MATCH);
         $this->validator = $validator;
     }
     return $this->validator;
 }
Пример #4
0
 /**
  * @return RegexValidator
  */
 public function getValidator()
 {
     if (null === $this->validator) {
         $validator = new RegexValidator('/' . self::PHONE_FORMAT . '/');
         $validator->setMessage('Must be a 10-digit phone number with area code', RegexValidator::NOT_MATCH);
         $this->validator = $validator;
     }
     return $this->validator;
 }
Пример #5
0
 /**
  * Get a validator if none has been set.
  * https://github.com/posabsolute/jQuery-Validation-Engine/issues/265
  * @return ValidatorInterface
  */
 public function getValidator()
 {
     if (null === $this->validator) {
         $validator = new RegexValidator('/^([\\+][0-9]{1,3}[ \\.\\-])?([\\(]{1}[0-9]{1,6}[\\)])?([0-9 \\.\\-\\/]{3,20})((x|ext|extension)[ ]?[0-9]{1,4})?$/');
         $validator->setMessage('Please enter a phone Number. You can use the intenational format. Only digits and \'+\'.', RegexValidator::NOT_MATCH);
         $this->validator = $validator;
     }
     return $this->validator;
 }
Пример #6
0
 public function buildFilter()
 {
     /******************************************************************
      * Isto é um exemplo de como realizar a configurações do filtro,
      * O importante é registrar o campos do formulário pedidos no exercícios
      **********************************************************************/
     // filter & validate by fields
     $category = new Input('category');
     $category->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags')->attachByName('StringToLower');
     $category->getValidatorChain()->attachByName('InArray', array('haystack' => $this->getCategories()));
     $title = new Input('title');
     $title->getFilterChain()->attachByName('StringTrim')->attachByName('StripTags');
     $titleRegex = new Regex(array('pattern' => '/^[a-zA-Z0-9 ]*$/'));
     $titleRegex->setMessage('Title should only contain numbers, letters or spaces!');
     $title->getValidatorChain()->attach($titleRegex)->attachByName('StringLength', array('min' => 1, 'max' => 128));
     $photo = new Input('photo_filename');
     $photo->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $photo->getValidatorChain()->attachByName('Regex', array('pattern' => '!^(http://)?[a-z0-9./_-]+(jp(e)?g|png)$!i'));
     $photo->setErrorMessage('Photo must be a URL or a valid filename ending with jpg or png');
     $price = new Input('price');
     $price->setAllowEmpty(TRUE);
     $price->getValidatorChain()->addByName('GreaterThan', array('min' => 0.0));
     $price->getFilterChain()->attach(new Float());
     // custom filter
     $expires = new Input('expires');
     $expires->setAllowEmpty(TRUE);
     $expires->getValidatorChain()->attachByName('InArray', array('haystack' => array_keys($this->getExpireDays())));
     $expires->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $city = new Input('cityCode');
     $city->setAllowEmpty(TRUE);
     $city->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $name = new Input('contact_name');
     $name->setAllowEmpty(TRUE);
     $name->getValidatorChain()->attachByName('Regex', array('pattern' => '/^[a-z0-9., -]{1,255}$/i'));
     $name->setErrorMessage('Name should only contain letters, numbers, and some punctuation.');
     $name->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $phone = new Input('contact_phone');
     $phone->setAllowEmpty(TRUE);
     $phone->getValidatorChain()->attachByName('Regex', array('pattern' => '/^\\+?\\d{1,4}(-\\d{3,4})+$/'));
     $phone->setErrorMessage('Phone number must be in this format: +nnnn-nnn-nnn-nnnn');
     $phone->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $email = new Input('contact_email');
     $email->setAllowEmpty(TRUE);
     $email->getValidatorChain()->attachByName('EmailAddress');
     $email->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $description = new Input('description');
     $description->setAllowEmpty(TRUE);
     $description->getValidatorChain()->attachByName('StringLength', array('min' => 1, 'max' => 4096));
     $description->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim');
     $delCode = new Input('delete_code');
     $delCode->setRequired(TRUE);
     $delCode->getValidatorChain()->addByName('Digits');
     $this->add($category)->add($title)->add($photo)->add($price)->add($expires)->add($city)->add($name)->add($phone)->add($email)->add($description)->add($delCode);
 }