/** * Instantiate an Input object for the supplied field call setAllowEmpty() * depending upon whether the field is required. * * @param Field $field * @return Input */ protected function instantiateInput(Field $field) { $input = new Input($field->getControlName()); if ($field->isRequired() && !$field->isType('boolean')) { $input->setAllowEmpty(false); } else { $input->setAllowEmpty(true); } return $input; }
/** * @return InputFilterInterface */ public function getInputFilter() { if (!$this->inputFilter) { $searchParam = new Input('search_param'); $searchParam->setAllowEmpty(false); $searchParam->setRequired(true); $radius = new Input('radius'); $radius->setAllowEmpty(true); $radius->setRequired(false); $city = new Input('city'); $city->setAllowEmpty(true); $city->setRequired(false); $state = new Input('state'); $state->setAllowEmpty(true); $state->setRequired(false); $postalCode = new Input('postal_code'); $postalCode->setAllowEmpty(true); $postalCode->setRequired(false); // $contactEmail = new Input('contact_email'); // $contactEmail ->setRequired(false); // $contactEmail ->setAllowEmpty(true) // ->getValidatorChain() // ->addValidator(new \Zend\Validator\EmailAddress()); $inputFilter = new InputFilter(); $inputFilter->add($searchParam)->add($radius)->add($city)->add($state)->add($postalCode); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
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); }
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); }
public function buildFilter() { $listingsId = new Input('listings_id'); $listingsId->getFilterChain()->attach(new StripTags())->attach(new StringTrim())->attach(new StringToLower()); $listingsId->getValidatorChain()->attachByName('Digits'); $deleteCode = new Input('delete_code'); $deleteCode->setAllowEmpty(TRUE); $deleteCode->getFilterChain()->attach(new StripTags())->attach(new StringTrim()); $deleteCode->getValidatorChain()->attachByName('Alnum', array('allowWhiteSpace' => false)); $this->add($listingsId)->add($deleteCode); }
/** * @return InputFilterInterface */ public function getInputFilter() { if (!$this->inputFilter) { $name = new Input('name'); $name->setAllowEmpty(true); $name->setRequired(false); $venueId = new Input('venue_id'); $venueId->setRequired(true); $type = new Input('type'); $type->setRequired(true); $type->allowEmpty(false); $url = new Input('url'); $url->setAllowEmpty(true); $url->setRequired(false); $startTime = new Input('start_time'); $startTime->setRequired(true); $startTime->allowEmpty(false); $endTime = new Input('end_time'); $endTime->setRequired(true); $endTime->allowEmpty(false); $startDate = new Input('start_date'); $startDate->setAllowEmpty(false); $startDate->setRequired(true); $endDate = new Input('end_date'); $endDate->setRequired(true); $endDate->allowEmpty(false); $minimumAge = new Input('minimum_age'); $minimumAge->setRequired(true); $minimumAge->allowEmpty(false); $willStop = new Input('will_stop'); $willStop->setRequired(true); $repetitions = new Input('repetitions'); $repetitions->setAllowEmpty(true); $repetitions->setRequired(false); $description = new Input('description'); $description->setAllowEmpty(true); $description->setRequired(false); $specialNotes = new Input('special_notes'); $specialNotes->setAllowEmpty(true); $specialNotes->setRequired(false); $costs = new Input('costs'); $costs->setAllowEmpty(true); $costs->setRequired(false); $contactEmail = new Input('contact_email'); $contactEmail->setRequired(false); $contactEmail->setAllowEmpty(true)->getValidatorChain()->addValidator(new \Zend\Validator\EmailAddress()); $inputFilter = new InputFilter(); $inputFilter->add($name)->add($type)->add($url)->add($venueId)->add($startTime)->add($endTime)->add($startDate)->add($endDate)->add($willStop)->add($minimumAge)->add($repetitions)->add($specialNotes)->add($description)->add($costs)->add($contactEmail); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
/** * Return an instance of InputFilter * * @return InputFilter */ public function getInputFilter() { if (!isset($this->inputFilter)) { $inputFilter = parent::getInputFilter(); // count $count = new Input('count'); $count->setAllowEmpty(true); $count->getFilterChain()->attach(new Int()); $count->getValidatorChain()->attach(new Digits()); $inputFilter->add($count); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
public function buildFilter() { $category = new Input('category'); $category->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim')->attachByName('StringToLower'); $category->getValidatorChain()->attachByName('InArray', array('haystack' => $this->getCategories())); $title = new Input('title'); $title->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $titleRegex = new Regex(array('pattern' => '/^[a-zA-Z0-9 ]*$/')); $title->getValidatorChain()->attach($titleRegex)->attachByName('StringLength', array('min' => 1, 'max' => 128)); $photo = new Input('photo_filename'); $photo->setRequired(FALSE); $photo->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $photo->getValidatorChain()->attachByName('Regex', array('pattern' => '!^(http(s)?://)?[a-z0-9./_-]+(jp(e)?g|png)$!i')); $photo->setErrorMessage('Photo must be a URL or a valid filename ending with jpg or png'); $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, spaces, . or -.'); $name->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $email = new Input('contact_email'); $email->setAllowEmpty(TRUE); $email->getValidatorChain()->attachByName('EmailAddress'); $email->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 the format +nnnn-nnn-nnn-nnnn'); $phone->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $city = new Input('city'); $city->setAllowEmpty(TRUE); $city->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $city->getValidatorChain()->attachByName('InArray', array('haystack' => PostForm::$cityCodes)); $price = new Input('price'); $price->setAllowEmpty(TRUE); $price->getValidatorChain()->attachByName('GreaterThan', array('min' => 0.0)); $price->getFilterChain()->attach(new Float()); $expires = new Input('expires'); $expires->setAllowEmpty(TRUE); $expires->getValidatorChain()->attachByName('InArray', array('haystack' => array_keys($this->getExpireDays()))); $expires->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $deleteCode = new Input('delete_code'); $deleteCode->setRequired(TRUE); $deleteCode->getValidatorChain()->attachByName('Digits'); $description = new Input('description'); $description->setAllowEmpty(TRUE); $description->getValidatorChain()->attachByName('StringLength', array('min' => 1, 'max' => 4096)); $description->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $this->add($category)->add($title)->add($photo)->add($name)->add($email)->add($phone)->add($city)->add($price)->add($expires)->add($deleteCode)->add($description); }
/** * @return InputFilterInterface */ public function getInputFilter() { if (!$this->inputFilter) { $searchParam = new Input('search_param'); $searchParam->setRequired(true); $searchCriteria = new Input('search_criteria'); $searchCriteria->setRequired(true); $eventId = new Input('event_id'); $eventId->setRequired(false); $eventId->setAllowEmpty(true); $inputFilter = new InputFilter(); $inputFilter->add($searchParam)->add($searchCriteria)->add($eventId); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
public function buildFilter() { $category = new Input('category'); $category->getFilterChain()->attach(new StripTags())->attach(new StringTrim())->attach(new StringToLower()); $category->getValidatorChain()->attach(new InArray(array('haystack' => $this->categories))); $title = new Input('title'); $title->getFilterChain()->attach(new StripTags())->attach(new StringTrim()); $title->getValidatorChain()->attachByName('Alnum', array('allowWhiteSpace' => TRUE))->attachByName('StringLength', array('options' => array('min' => 6, 'max' => 128))); $price = new Input('price'); $price->getFilterChain()->attach(new StripTags())->attach(new StringTrim()); $priceRegex = new \Zend\Validator\Regex(array('pattern' => '/^[0-9]{1,10}+(\\.[0-9]{1,2})?$/')); $priceRegex->setMessage('Preço deve ter no máximo 12 caracteres, incluindo opcionalmente 2 casas decimais separadas por ".".'); $price->getValidatorChain()->attach($priceRegex); $dateExpires = new Input('date_expires'); $dateExpires->setAllowEmpty(TRUE); $dateExpires->getValidatorChain()->attach(new InArray(array('haystack' => $this->dateExpires))); $description = new Input('description'); $description->setAllowEmpty(TRUE); $description->getFilterChain()->attach(new StripTags())->attach(new StringTrim()); $description->getValidatorChain()->attachByName('StringLength', array('options' => array('max' => 4096))); $photoFilename = new Input('photo_filename'); $photoFilename->setAllowEmpty(TRUE); $photoFilename->getValidatorChain()->attachByName('Regex', array('pattern' => '!^(http://)?[a-z0-9./_-]+(jp(e)?g|png)$!i')); $photoFilename->setErrorMessage('Photo must be a URL or a valid filename ending with jpg or png'); $contactName = new Input('contact_name'); $contactName->getFilterChain()->attach(new StripTags())->attach(new StringTrim()); $contactName->getValidatorChain()->attachByName('Regex', array('pattern' => '/^[a-z0-9., -]{1,255}$/i')); $contactName->setErrorMessage('Name should only contain letters, numbers, and some punctuation.'); $contactEmail = new Input('contact_email'); $contactEmail->setAllowEmpty(TRUE); $contactEmail->getFilterChain()->attach(new StripTags())->attach(new StringTrim()); $contactEmail->getValidatorChain()->attachByName('EmailAddress'); $contactPhone = new Input('contact_phone'); $contactPhone->setAllowEmpty(TRUE); $contactPhone->getFilterChain()->attach(new StripTags())->attach(new StringTrim()); $contactPhone->getValidatorChain()->attachByName('Regex', array('pattern' => '/^(\\([0-9]{2}\\))\\s([9]{1})?([0-9]{4})-([0-9]{4})$/')); $contactPhone->setErrorMessage('Contato deve ter o seguinte formato:(99) 9999-9999 ou (99) 99999-9999'); $cityCode = new Input('cityCode'); $cityCode->setAllowEmpty(TRUE); $cityCode->getFilterChain()->attach(new StripTags())->attach(new StringTrim()); $cityCode->getValidatorChain()->attach(new InArray(array('haystack' => array_keys($this->cities)))); $deleteCode = new Input('delete_code'); $deleteCode->setAllowEmpty(TRUE); $deleteCode->getFilterChain()->attach(new StripTags())->attach(new StringTrim()); $deleteCode->getValidatorChain()->attachByName('Alnum', array('allowWhiteSpace' => TRUE)); $this->add($category)->add($title)->add($price)->add($dateExpires)->add($description)->add($photoFilename)->add($contactName)->add($contactEmail)->add($contactPhone)->add($cityCode)->add($deleteCode); }
public function getInputFilter() { if ($this->filter == null) { $this->filter = new InputFilter(); $inputFilter = parent::getInputFilter(); $email = new Input('email'); $email->setRequired(true); $email->setAllowEmpty(false); $objectExists = new ObjectExists(array('object_repository' => $this->objectManager->getRepository(User::getClass()), 'fields' => 'email')); $objectExists->setMessage($this->translator->translate('forgotPassword.email.notExists'), ObjectExists::ERROR_NO_OBJECT_FOUND); $emailAddress = new EmailAddress(); $emailAddress->setMessage($this->translator->translate('forgotPassword.email.invalidFormat'), $emailAddress::INVALID_FORMAT); $email->getValidatorChain()->attach($emailAddress, true)->attach($objectExists); $this->filter->add($email); } return $this->filter; }
public function getInputFilter() { $this->filter = parent::getInputFilter(); $moneyValidator = new MoneyValidator(); $delayPercent = new Input('delayPercent'); $delayPercent->setRequired(false); $delayPercent->setAllowEmpty(true); $delayPercent->getValidatorChain()->attach($moneyValidator); $this->filter->add($delayPercent); $digits = new Digits(); $deadlineDays = new Input('deadlineDays'); $deadlineDays->setRequired(false); $deadlineDays->setAllowEmpty(true); $deadlineDays->getValidatorChain()->attach($digits); $this->filter->add($deadlineDays); return $this->filter; }
/** * @param ServiceLocatorInterface $serviceLocator * * @return InputFilter */ public function createService(ServiceLocatorInterface $serviceLocator) { $username = new Input(); $username->setName('username'); $username->setRequired(true); $username->setAllowEmpty(false); $username->getFilterChain()->attach(new StringTrim())->attach(new StripTags()); $password = new Input(); $password->setName('password'); $password->setRequired(true); $password->setAllowEmpty(false); $password->getFilterChain()->attach(new StringTrim())->attach(new StripTags()); $password->getValidatorChain()->attach($serviceLocator->get('UghAuthentication\\Authentication\\Validator\\Authentication')); $inputFilter = new InputFilter(); $inputFilter->add($username); $inputFilter->add($password); return $inputFilter; }
/** * @return InputFilterInterface */ public function getInputFilter() { if (!$this->inputFilter) { $name = new Input('name'); $name->setRequired(true); $address1 = new Input('address_1'); $address1->setRequired(true); $address2 = new Input('address_2'); $address2->setAllowEmpty(true); $address2->setRequired(false); $city = new Input('city'); $city->setRequired(true); $state = new Input('state'); $state->setRequired(false); $state->setAllowEmpty(true); $country = new Input('country'); $country->setRequired(true); $postalCode = new Input('postal_code'); $postalCode->setRequired(false); $postalCode->setAllowEmpty(true); $url = new Input('url'); $url->setAllowEmpty(true); $url->setRequired(false); $specialNotes = new Input('special_notes'); $specialNotes->setAllowEmpty(true); $specialNotes->setRequired(false); $description = new Input('description'); $description->setAllowEmpty(true); $description->setRequired(false); $minimumAge = new Input('minimum_age'); $minimumAge->setRequired(true); $contactEmail = new Input('contact_email'); $contactEmail->setAllowEmpty(true); $contactEmail->setRequired(false)->getValidatorChain()->addValidator(new \Zend\Validator\EmailAddress()); $type = new Input('type'); $type->setRequired(true); $inputFilter = new InputFilter(); $inputFilter->add($name)->add($address1)->add($address2)->add($city)->add($state)->add($country)->add($postalCode)->add($url)->add($description)->add($specialNotes)->add($minimumAge)->add($contactEmail)->add($type); $this->inputFilter = $inputFilter; } return $this->inputFilter; }
public function getInputFilter() { if ($this->filter == null) { $this->filter = new InputFilter(); $code = new Input('code'); $code->setRequired(false); $code->setAllowEmpty(true); $this->filter->add($code); $digits = new Digits(); $value = new Input('value'); $value->setRequired(false); $value->setAllowEmpty(true); $value->getValidatorChain()->attach($digits); $this->filter->add($value); $comment = new Input('comment'); $comment->setRequired(false); $comment->setAllowEmpty(true); $this->filter->add($comment); } return $this->filter; }
/** * Constructor * * @param array $modes Array of valid modes * @param array $units Array of valid units * @param array $languages Array of valid languages * * @return void */ public function __construct($modes = array(), $units = array(), $languages = array()) { // mode $mode = new Input('mode'); $mode->allowEmpty(false); $mode->getFilterChain()->attach(new StringToLower()); $mode->getValidatorChain()->attach(new InArray(array('haystack' => $modes, 'messages' => array(InArray::NOT_IN_ARRAY => 'The supplied mode is not valid'))), true); // units $unit = new Input('units'); $unit->allowEmpty(false); $unit->getFilterChain()->attach(new StringToLower()); $unit->getValidatorChain()->attach(new InArray(array('haystack' => $units, 'messages' => array(InArray::NOT_IN_ARRAY => 'The supplied unit is not valid'))), true); // language $language = new Input('language'); $language->allowEmpty(false); $language->getFilterChain()->attach(new StringToLower()); $language->getValidatorChain()->attach(new InArray(array('haystack' => $languages, 'messages' => array(InArray::NOT_IN_ARRAY => 'The supplied language is invalid'))), true); // query $query = new Input('query'); $query->setAllowEmpty(true); $query->getFilterChain()->attach(new StringToLower()); $query->getValidatorChain()->attach(new StringLength(array('min' => 1, 'max' => 100, 'encoding' => 'UTF-8', 'messages' => array(StringLength::INVALID => 'The supplied query should be a string', StringLength::TOO_LONG => 'The supplied query should be no longer than 100 chars', StringLength::TOO_SHORT => 'The supplied query should be at least 1 character'))), true); // latitude $latitude = new Input('latitude'); $latitude->setAllowEmpty(true); $latitude->getValidatorChain()->attach(new Regex(array('pattern' => '#\\A[-|+]?[\\d]{1,2}(?:[\\.][\\d]*)?\\z#')), true); // longitude $longitude = new Input('longitude'); $longitude->setAllowEmpty(true); $longitude->getValidatorChain()->attach(new Regex(array('pattern' => '#\\A[-|+]?[\\d]{1,3}(?:[\\.][\\d]*)?\\z#')), true); // id $id = new Input('id'); $id->setAllowEmpty(true); $id->getValidatorChain()->attach(new Digits(), true); // apiKey $apiKey = new Input('apiKey'); $apiKey->setAllowEmpty(true); $this->add($mode)->add($unit)->add($language)->add($query)->add($latitude)->add($longitude)->add($id)->add($apiKey); }
public function prepareFilters(array $categories) { $category = new Input('category'); $category->setAllowEmpty(TRUE); $category->getFilterChain()->attach(new Filter\StringToLower())->attachByName('StripTags')->attachByName('StringTrim'); $title = new Input('title'); $title->setAllowEmpty(TRUE); $title->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $priceMin = new Input('priceMin'); $priceMin->setAllowEmpty(TRUE); $priceFilter = new Float(); $priceMin->getFilterChain()->attach($priceFilter); $priceMax = new Input('priceMax'); $priceMax->setAllowEmpty(TRUE); $priceFilter = new Float(); $priceMax->getFilterChain()->attach($priceFilter); $expires = new Input('expires'); $expires->setAllowEmpty(TRUE); $expires->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $city = new Input('city'); $city->setAllowEmpty(TRUE); $city->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $country = new Input('country'); $country->setAllowEmpty(TRUE); $country->getFilterChain()->attachByName('StringToUpper')->attachByName('StripTags')->attachByName('StringTrim'); $name = new Input('name'); $name->setAllowEmpty(TRUE); $name->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $phone = new Input('phone'); $phone->setAllowEmpty(TRUE); $phone->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $email = new Input('email'); $email->setAllowEmpty(TRUE); $email->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $description = new Input('description'); $description->setAllowEmpty(TRUE); $description->getFilterChain()->attachByName('StripTags')->attachByName('StringTrim'); $this->add($category)->add($title)->add($priceMin)->add($priceMax)->add($expires)->add($city)->add($country)->add($name)->add($phone)->add($email)->add($description); }
public function getInputFilter() { if ($this->filter == null) { $this->filter = new InputFilter(); $password = new Input('password'); $password->setRequired(true); $password->setAllowEmpty(false); $length = new StringLength(); $length->setMax(20); $length->setMin(5); $length->setMessage($this->translator->translate('newPassword.password.incorrectLength'), StringLength::TOO_LONG); $length->setMessage($this->translator->translate('newPassword.password.incorrectLength'), StringLength::TOO_SHORT); $password->getValidatorChain()->attach($length); $this->filter->add($password); $passowordRepeat = new Input('passwordRepeat'); $passowordRepeat->setRequired(true); $passowordRepeat->setAllowEmpty(false); $passowordRepeat->getValidatorChain()->attach(new Identical('password')); $this->filter->add($passowordRepeat); } return $this->filter; }
public function getInputFilter() { if ($this->filter == null) { $this->filter = new InputFilter(); $paymentType = new Input('paymentType'); $paymentType->setRequired(true); $paymentType->setAllowEmpty(false); $this->filter->add($paymentType); $type = new Input('type'); $type->setRequired(true); $type->setAllowEmpty(false); $this->filter->add($type); $paymentDate = new Input('paymentDate'); $paymentDate->setRequired(true); $paymentDate->setAllowEmpty(false); $this->filter->add($paymentDate); $name = new Input('name'); $name->setRequired(false); $name->setAllowEmpty(true); $this->filter->add($name); $invoiceText = new Input('invoiceText'); $invoiceText->setRequired(false); $invoiceText->setAllowEmpty(true); $this->filter->add($invoiceText); $invoiceNumber = new Input('invoiceNumber'); $invoiceNumber->setRequired(false); $invoiceNumber->setAllowEmpty(true); $this->filter->add($invoiceNumber); $invoiceId = new Input('invoiceId'); $invoiceId->setRequired(false); $invoiceId->setAllowEmpty(true); $this->filter->add($invoiceId); $purchInvoiceText = new Input('purchInvoiceText'); $purchInvoiceText->setRequired(false); $purchInvoiceText->setAllowEmpty(true); $this->filter->add($purchInvoiceText); $purchInvoiceNumber = new Input('purchInvoiceNumber'); $purchInvoiceNumber->setRequired(false); $purchInvoiceNumber->setAllowEmpty(true); $this->filter->add($purchInvoiceNumber); $purchInvoiceId = new Input('purchInvoiceId'); $purchInvoiceId->setRequired(false); $purchInvoiceId->setAllowEmpty(true); $this->filter->add($purchInvoiceId); $referenceNumber = new Input('referenceNumber'); $referenceNumber->setRequired(false); $referenceNumber->setAllowEmpty(true); $this->filter->add($referenceNumber); $moneyValidator = new MoneyValidator(); $sum = new Input('sum'); $sum->setRequired(true); $sum->setAllowEmpty(false); $sum->getValidatorChain()->attach($moneyValidator); $this->filter->add($sum); $description = new Input('description'); $description->setRequired(false); $description->setAllowEmpty(true); $this->filter->add($description); $payerIban = new Input('payerIban'); $payerIban->setRequired(false); $payerIban->setAllowEmpty(true); $this->filter->add($payerIban); $archiveSign = new Input('archiveSign'); $archiveSign->setRequired(false); $archiveSign->setAllowEmpty(true); $this->filter->add($archiveSign); } return $this->filter; }
/** * Build a Fields object that can be used for displaying or editing * subscriptions. * * @todo Refactor this into a separate class. * * @param string $editUrl * @param Fields $componentFields * @return Fields */ public function buildFields($editUrl, Fields $componentFields) { $fields = new Fields(); $fields->add('recipients')->setLabel('Recipients')->setNote('Enter one or more email addresses separated by commas.')->setVisible(true)->assignHelperCallback('TableCell.Content', function (TableCellHelper $helper, array $rowData) use($editUrl) { return $helper->getView()->escapeHtml($this->renderRecipients($rowData['dewdrop_notification_subscription_id'])); })->setEditable(true)->assignHelperCallback('EditControl.Control', function ($helper, View $view) { return $view->inputText('recipients', $this->renderRecipients($view->getRequest()->getQuery('dewdrop_notification_subscription_id')), 'form-control'); })->assignHelperCallback('InputFilter', function ($helper) { $input = new Input('recipients'); $input->setAllowEmpty(false); return $input; })->add($this->field('dewdrop_notification_frequency_id'))->add('fields')->setLabel('Which fields would you like to include in the notification emails?')->setEditable(true)->assignHelperCallback('EditControl.Control', function ($helper, View $view) use($componentFields) { $options = array(); foreach ($componentFields->getVisibleFields() as $id => $field) { $options[$id] = $field->getLabel(); } return $view->checkboxList('fields', $options, $this->getSelectedFields($view->getRequest()->getQuery('dewdrop_notification_subscription_id'), $options)); })->assignHelperCallback('InputFilter', function ($helper) { $input = new Input('fields'); $input->setAllowEmpty(false); return $input; }); return $fields; }
public function testValidationMarksInputInvalidWhenRequiredAndAllowEmptyFlagIsFalse() { $filter = new InputFilter(); $foo = new Input(); $foo->getValidatorChain()->addValidator(new Validator\StringLength(3, 5)); $foo->setRequired(true); $foo->setAllowEmpty(false); $bar = new Input(); $bar->getValidatorChain()->addValidator(new Validator\Digits()); $bar->setRequired(true); $filter->add($foo, '') ->add($bar, 'bar'); $data = array('bar' => 124); $filter->setData($data); $this->assertFalse($filter->isValid()); }
public function getInputFilter() { if ($this->filter == null) { $this->filter = new InputFilter(); $name = new Input('name'); $name->setRequired(false); $name->setAllowEmpty(true); $this->filter->add($name); $code = new Input('code'); $code->setRequired(false); $code->setAllowEmpty(true); $this->filter->add($code); $moneyValidator = new MoneyValidator(); $salesPrice = new Input('salesPrice'); $salesPrice->setRequired(false); $salesPrice->setAllowEmpty(true); $salesPrice->getValidatorChain()->attach($moneyValidator); $this->filter->add($salesPrice); $digits = new Digits(); $qty = new Input('qty'); $qty->setRequired(false); $qty->setAllowEmpty(true); $qty->getValidatorChain()->attach($digits); $this->filter->add($qty); $description = new Input('description'); $description->setRequired(false); $description->setAllowEmpty(true); $this->filter->add($description); $uom = new Input('uom'); $uom->setRequired(false); $uom->setAllowEmpty(true); $this->filter->add($uom); } return $this->filter; }
public function getInputFilter() { if ($this->filter == null) { $this->filter = new InputFilter(); $name = new Input('name'); $name->setRequired(false); $name->setAllowEmpty(true); $this->filter->add($name); $regNo = new Input('regNo'); $regNo->setRequired(false); $regNo->setAllowEmpty(true); $this->filter->add($regNo); $kmkrNo = new Input('kmkrNo'); $kmkrNo->setRequired(false); $kmkrNo->setAllowEmpty(true); $this->filter->add($kmkrNo); $address = new Input('address'); $address->setRequired(false); $address->setAllowEmpty(true); $this->filter->add($address); $zip = new Input('zip'); $zip->setRequired(false); $zip->setAllowEmpty(true); $this->filter->add($zip); $country = new Input('country'); $country->setRequired(false); $country->setAllowEmpty(true); $this->filter->add($country); $city = new Input('city'); $city->setRequired(false); $city->setAllowEmpty(true); $this->filter->add($city); $url = new Input('url'); $url->setRequired(false); $url->setAllowEmpty(true); $this->filter->add($url); $phone = new Input('phone'); $phone->setRequired(false); $phone->setAllowEmpty(true); $this->filter->add($phone); $email = new Input('email'); $email->setRequired(false); $email->setAllowEmpty(true); $this->filter->add($email); $mob = new Input('mob'); $mob->setRequired(false); $mob->setAllowEmpty(true); $this->filter->add($mob); } return $this->filter; }
public function getInputFilter() { if ($this->filter == null) { $this->filter = new InputFilter(); $customer = new Input('customer'); $customer->setRequired(false); $customer->setAllowEmpty(true); $this->filter->add($customer); $supplier = new Input('supplier'); $supplier->setRequired(false); $supplier->setAllowEmpty(true); $this->filter->add($supplier); $supplierDocNumber = new Input('supplierDocNumber'); $supplierDocNumber->setRequired(false); $supplierDocNumber->setAllowEmpty(true); $this->filter->add($supplierDocNumber); $paymentType = new Input('paymentType'); $paymentType->setRequired(false); $paymentType->setAllowEmpty(true); $this->filter->add($paymentType); $comment = new Input('comment'); $comment->setRequired(false); $comment->setAllowEmpty(true); $this->filter->add($comment); $vat = new Input('vat'); $vat->setRequired(false); $vat->setAllowEmpty(true); $this->filter->add($vat); $docDate = new Input('docDate'); $docDate->setRequired(true); $docDate->setAllowEmpty(false); $this->filter->add($docDate); $digits = new Digits(); $deadlineDays = new Input('deadlineDays'); $deadlineDays->setRequired(false); $deadlineDays->setAllowEmpty(true); $deadlineDays->getValidatorChain()->attach($digits); $this->filter->add($deadlineDays); $moneyValidator = new MoneyValidator(); $delayPercent = new Input('delayPercent'); $delayPercent->setRequired(false); $delayPercent->setAllowEmpty(true); $delayPercent->getValidatorChain()->attach($moneyValidator); $this->filter->add($delayPercent); $greaterThan = new GreaterThan(); $greaterThan->setMin(0.001); $amount = new Input('amount'); $amount->setRequired(true); $amount->setAllowEmpty(false); $amount->getValidatorChain()->attach($moneyValidator)->attach($greaterThan); $this->filter->add($amount); $taxAmount = new Input('taxAmount'); $taxAmount->setRequired(false); $taxAmount->setAllowEmpty(true); $taxAmount->getValidatorChain()->attach($moneyValidator); $this->filter->add($taxAmount); $amountTax = new Input('amountTax'); $amountTax->setRequired(true); $amountTax->setAllowEmpty(false); $amountTax->getValidatorChain()->attach($moneyValidator); $this->filter->add($amountTax); } return $this->filter; }
/** * Pre-process form: set id if needed and and set */ private function preProcessForm() { $xpath = new DOMXPath($this->document); $elements = $xpath->query('//input | //textarea | //div[@data-input-name]'); /** @var DOMElement $element */ foreach ($elements as $element) { // Set some basic vars $name = $element->getAttribute('name'); if (!$name) { $name = $element->getAttribute('data-input-name'); } if (!$name) { // At least a name is needed to submit a value. // Silently continue, might be a submit button. continue; } // Create an id if needed, this speeds up finding the element again $id = $element->getAttribute('id'); if (!$id) { $id = md5(spl_object_hash($element)); $element->setAttribute('id', $id); } $this->nameIdXref[$name] = $id; // Detect element type $type = $element->getAttribute('type'); if ($element->tagName == 'textarea') { $type = 'textarea'; } // Add validation if (isset($this->formElements[$type])) { $validator = new $this->formElements[$type](); } else { // Create a default validator $validator = new $this->formElements['text'](); } if ($this->inputFilter->has($name)) { $input = $this->inputFilter->get($name); } else { // No input found for element, create a new one $input = new Input($name); // Enforce properties so the NotEmpty validator is automatically added, // we'll take care of this later. $input->setRequired(false); $input->setAllowEmpty(true); $this->inputFilter->add($input); } // Process element and attach filters and validators $validator($element, $input); } }
public function testGetRequiredNotEmptyValidationMessages() { $filter = new InputFilter(); $foo = new Input(); $foo->setRequired(true); $foo->setAllowEmpty(false); $filter->add($foo, 'foo'); $data = array('foo' => null); $filter->setData($data); $this->assertFalse($filter->isValid()); $messages = $filter->getMessages(); $this->assertArrayHasKey('foo', $messages); $this->assertNotEmpty($messages['foo']); }
protected function getNameInput() { $hrefLang = new Input('name'); $hrefLang->setAllowEmpty(true); return $hrefLang; }
public function testAllowEmptyFlagIsMutable() { $this->input->setAllowEmpty(true); $this->assertTrue($this->input->allowEmpty()); }
public function testAllowEmptyFlagIsMutable() { $input = new Input('foo'); $input->setAllowEmpty(true); $this->assertTrue($input->allowEmpty()); }
public function getInputFilter() { if ($this->filter == null) { $this->filter = new InputFilter(); $code = new Input('code'); $code->setRequired(true); $code->setAllowEmpty(false); $this->filter->add($code); $name = new Input('name'); $name->setRequired(true); $name->setAllowEmpty(false); $this->filter->add($name); $titleEt = new Input('titleEt'); $titleEt->setRequired(true); $titleEt->setAllowEmpty(false); $this->filter->add($titleEt); $titleEn = new Input('titleEn'); $titleEn->setRequired(true); $titleEn->setAllowEmpty(false); $this->filter->add($titleEn); $contentEt = new Input('contentEt'); $contentEt->setRequired(true); $contentEt->setAllowEmpty(false); $this->filter->add($contentEt); $contentEn = new Input('contentEn'); $contentEn->setRequired(true); $contentEn->setAllowEmpty(false); $this->filter->add($contentEn); } return $this->filter; }