/** * Is the data set valid? * * @return bool */ public function isValid() { $this->messages = []; try { $this->validationFactory->createInputFilter($this->data); return true; } catch (\Exception $e) { $this->messages['inputFilter'] = $e->getMessage(); return false; } }
public function getInputFilter() { $factory = new Factory; return $factory->createInputFilter(array( 'type' => 'ZF\Apigility\Admin\InputFilter\Authentication\OAuth2InputFilter', )); }
public function getInputFilter() { if (!$this->filter) { $factory = new InputFilterFactory(); $inputFilterSpec = array('id' => array('required' => false), 'block_id' => array('required' => false), 'href' => array('required' => false), 'title' => array('required' => true), 'type' => array('required' => true), 'file' => array('required' => false), 'link' => array('required' => false, 'validators' => array(new UrlValidator())), 'page' => array('required' => false), 'entity_id' => array('required' => false), 'position' => array('required' => false)); $data = $this->data; // if ($this->getName()){ // $name = str_replace(']','', $this->getName()); // $name = explode('[', $name); // while (!empty($name)){ // $key = array_shift($name); // $data = $data[$key]; // } // } switch ($data['type']) { case 'link': $inputFilterSpec['link']['required'] = true; break; case 'page': $inputFilterSpec['page']['required'] = true; break; case 'file': $inputFilterSpec['file']['required'] = true; break; } $this->filter = $factory->createInputFilter($inputFilterSpec); } return $this->filter; }
/** * Create service with name * * @param ServiceLocatorInterface $serviceLocator * @param $name * @param $requestedName * @return mixed */ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { $config = $serviceLocator->get('Config'); $zohoConfig = $config['zoho']; $resourceConfig = $config['zoho']['resources'][$requestedName]; $resource = new Resource($zohoConfig['auth_token'], $zohoConfig['organization_id']); $resource->setPath($resourceConfig['path']); $resource->setCollectionName($resourceConfig['collectionName']); $entityClass = array_key_exists('entityClass', $resourceConfig) ? $resourceConfig['entityClass'] : str_replace('Resource', 'Entity', $requestedName); $resource->setEntityClass($entityClass); $resource->setEntityName($resourceConfig['entityName']); if (isset($resourceConfig['input-filter']) && is_array($resourceConfig['input-filter'])) { $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter($resourceConfig['input-filter']); $resource->setInputFilter($inputFilter); } $hydratorManager = $serviceLocator->get('HydratorManager'); $hydratorName = str_replace('Entity', 'Hydrator', $entityClass); if ($hydratorManager->has($hydratorName)) { $hydrator = $hydratorManager->get($hydratorName); } else { $hydrator = new ClassMethods(); } $resource->setHydrator($hydrator); return $resource; }
public function init() { $this->setName('ef'); $this->add(array('name' => 'ef-name', 'type' => 'Text', 'attributes' => array('id' => 'ef-name', 'style' => 'width: 320px'), 'options' => array('label' => 'Name'))); $this->add(array('name' => 'ef-description', 'type' => 'Textarea', 'attributes' => array('id' => 'ef-description', 'class' => 'wysiwyg-editor', 'style' => 'width: 320px; height: 180px;'), 'options' => array('label' => 'Description'))); $this->add(array('name' => 'ef-date-start', 'type' => 'Text', 'attributes' => array('id' => 'ef-date-start', 'class' => 'datepicker', 'style' => 'width: 110px;'), 'options' => array('label' => 'Date (Start)'))); $this->add(array('name' => 'ef-time-start', 'type' => 'Text', 'attributes' => array('id' => 'ef-time-start', 'style' => 'width: 110px;'), 'options' => array('label' => 'Time (Start)'))); $this->add(array('name' => 'ef-date-end', 'type' => 'Text', 'attributes' => array('id' => 'ef-date-end', 'class' => 'datepicker', 'style' => 'width: 110px;'), 'options' => array('label' => 'Date (End)'))); $this->add(array('name' => 'ef-time-end', 'type' => 'Text', 'attributes' => array('id' => 'ef-time-end', 'style' => 'width: 110px;'), 'options' => array('label' => 'Time (End)'))); $squareOptions = array('null' => 'All squares'); foreach ($this->squareManager->getAll() as $sid => $square) { $squareOptions[$sid] = $square->get('name'); } $this->add(array('name' => 'ef-sid', 'type' => 'Select', 'attributes' => array('id' => 'ef-sid', 'style' => 'width: 124px'), 'options' => array('label' => 'Square', 'value_options' => $squareOptions))); $this->add(array('name' => 'ef-capacity', 'type' => 'Text', 'attributes' => array('id' => 'ef-capacity', 'style' => 'width: 110px;'), 'options' => array('label' => 'Capacity', 'notes' => 'How many people can participate?'))); $this->add(array('name' => 'ef-notes', 'type' => 'Textarea', 'attributes' => array('id' => 'ef-notes', 'style' => 'width: 250px; height: 48px;'), 'options' => array('label' => 'Notes', 'notes' => 'These are only visible for administration'))); $this->add(array('name' => 'ef-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'id' => 'ef-submit', 'class' => 'default-button', 'style' => 'width: 200px;'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('ef-name' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true))), 'ef-description' => array('required' => false, 'filters' => array(array('name' => 'StringTrim'))), 'ef-date-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }, 'message' => 'Invalid date')))), 'ef-time-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^[0-9]?[0-9]:[0-9][0-9]$/', 'message' => 'Please provide the time in format HH:MM')))), 'ef-date-end' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }, 'message' => 'Invalid date')))), 'ef-time-end' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^[0-9]?[0-9]:[0-9][0-9]$/', 'message' => 'Please provide the time in format HH:MM')))), 'ef-capacity' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Digits', 'options' => array('message' => 'Please type a number here')))), 'ef-notes' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')))))); }
public function init() { $this->setName('eef'); $this->add(array('name' => 'eef-email1', 'type' => 'Text', 'attributes' => array('id' => 'eef-email1', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Please provide your email address'))); $this->add(array('name' => 'eef-email2', 'type' => 'Text', 'attributes' => array('id' => 'eef-email2', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Please type your email address again<br>to prevent typing errors'))); $this->add(array('name' => 'eef-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Update email address', 'class' => 'default-button'))); /* Input filters */ $userManager = $this->userManager; $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('eef-email1' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your email address here'), 'break_chain_on_failure' => true), array('name' => 'EmailAddress', 'options' => array('useMxCheck' => true, 'message' => 'Please type your correct email address here', 'messages' => array('emailAddressInvalidMxRecord' => 'We could not verify your email provider')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { $blacklist = getcwd() . '/data/res/blacklist-emails.txt'; if (is_readable($blacklist)) { $blacklistContent = file_get_contents($blacklist); $blacklistDomains = explode("\r\n", $blacklistContent); foreach ($blacklistDomains as $blacklistDomain) { $blacklistPattern = str_replace('.', '\\.', $blacklistDomain); if (preg_match('/' . $blacklistPattern . '$/', $value)) { return false; } } } return true; }, 'message' => 'Trash mail addresses are currently blocked - sorry'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) use($userManager) { if ($userManager->getBy(array('email' => $value))) { return false; } else { return true; } }, 'message' => 'This email address has already been registered')))), 'eef-email2' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your email address here'), 'break_chain_on_failure' => true), array('name' => 'Identical', 'options' => array('token' => 'eef-email1', 'message' => array('Both email addresses must be identical')))))))); }
/** * Init Module form * * @return void */ public function init() { $this->setAttribute('class', 'relative'); $fileInfo = new Info(); $modulesInfos = array(); $options = array('' => 'Select an option'); foreach ($this->getServiceLocator()->get('ModulesList') as $path => $dir) { $options[$dir] = $dir; $configFile = $path . '/module.info'; if ($fileInfo->fromFile($configFile) === true) { $modulesInfos[$dir] = $fileInfo->render(); } } $collection = new ModuleCollection(); $modules = $collection->getModules(); foreach ($modules as $module) { if (in_array($module->getName(), $options)) { unset($options[$module->getName()]); unset($modulesInfos[$module->getName()]); } } $module = new Element\Select('module'); $module->setLabel('Module')->setLabelAttributes(array('class' => 'required')); $module->setAttribute('id', 'module')->setAttribute('class', 'form-control')->setAttribute('modules_info', $modulesInfos)->setValueOptions($options); $this->add($module); $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('module' => array('name' => 'module', 'required' => true, 'validators' => array(array('name' => 'not_empty'))))); $this->setInputFilter($inputFilter); }
public function getInputFilter() { $factory = new Factory(); return $factory->createInputFilter(array( 'type' => 'ZF\Apigility\Admin\InputFilter\VersionInputFilter', )); }
public function init() { $this->setName('bf'); $this->add(array('name' => 'bf-date-start', 'type' => 'Text', 'attributes' => array('id' => 'bf-date-start', 'style' => 'width: 80px;'), 'options' => array('label' => 'Date (Start)'))); $this->add(array('name' => 'bf-date-end', 'type' => 'Text', 'attributes' => array('id' => 'bf-date-end', 'style' => 'width: 80px;'), 'options' => array('label' => 'Date (End)'))); $this->add(array('name' => 'bf-repeat', 'type' => 'Select', 'attributes' => array('id' => 'bf-repeat', 'style' => 'width: 124px'), 'options' => array('label' => 'Repeat', 'value_options' => Booking::$repeatOptions))); $this->add(array('name' => 'bf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'id' => 'bf-submit', 'class' => 'default-button', 'style' => 'width: 125px;'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('bf-date-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }, 'message' => 'Invalid date')))), 'bf-date-end' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) { try { new \DateTime($value); return true; } catch (\Exception $e) { return false; } }, 'message' => 'Invalid date'))))))); }
/** * @inheritdoc */ public function validate(array $data, $method = null) { if ($method !== null && $method !== 'POST') { // Not a post request, skip validation return new ValidationResult([], [], [], $method); } $inputFilter = $this->factory->createInputFilter([]); // Add all validators and filters to the InputFilter $this->buildInputFilterFromForm($inputFilter); $inputFilter->setData($data); $messages = []; // Do some validation if (!$inputFilter->isValid()) { foreach ($inputFilter->getInvalidInput() as $message) { $messages[$message->getName()] = $message->getMessages(); } } // Get the submit button $submitName = null; foreach ($this->getSubmitStateNodeList() as $name) { if (array_key_exists($name, $data)) { $submitName = $name; } } // Return validation result return new ValidationResult($inputFilter->getRawValues(), $inputFilter->getValues(), $messages, $method, $submitName); }
/** * Init Module form * * @return void */ public function init() { $showEmail = new Element\Checkbox('show_email'); $showEmail->setLabel('Show email'); $showEmail->setAttribute('required', 'required')->setAttribute('id', 'show-email'); $username = new Element\Text('username'); $username->setLabel('Username'); $username->setAttribute('required', 'required')->setAttribute('id', 'username'); $email = new Element\Text('email'); $email->setLabel('Email'); $email->setAttribute('required', 'required')->setAttribute('id', 'email'); $message = new Element\Textarea('message'); $message->setLabel('Message'); $message->setAttribute('required', 'required')->setAttribute('id', 'message'); $captchaImage = new CaptchaImage(array('font' => GC_PUBLIC_PATH . '/backend/fonts/arial.ttf', 'width' => 250, 'height' => 50, 'dotNoiseLevel' => 40, 'lineNoiseLevel' => 3)); $captchaImage->setImgDir(GC_PUBLIC_PATH . '/frontend/tmp'); $captchaImage->setImgUrl('/frontend/tmp'); $captcha = new Element\Captcha('captcha'); $captcha->setLabel('Please verify you are human')->setCaptcha($captchaImage)->setAttribute('required', 'required')->setAttribute('id', 'captcha'); $this->add($showEmail); $this->add($username); $this->add($email); $this->add($message); $this->add($captcha); $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('show_email' => array('name' => 'show_email', 'required' => false), 'username' => array('name' => 'username', 'required' => true), 'email' => array('name' => 'email', 'required' => true, 'validators' => array(array('name' => 'email_address'))), 'message' => array('name' => 'message', 'required' => true), 'captcha' => $captcha->getInputSpecification())); $this->setInputFilter($inputFilter); }
public function testInputSpecificationFilterIfSecondNotProvided() { $element = new DateTimeSelectElement('test'); $factory = new InputFilterFactory(); $inputFilter = $factory->createInputFilter(array('test' => $element->getInputSpecification())); $inputFilter->setData(array('test' => array('year' => '2013', 'month' => '02', 'day' => '07', 'hour' => '03', 'minute' => '14'))); $this->assertTrue($inputFilter->isValid()); }
public function init() { $this->setName('epf'); $this->add(array('name' => 'epf-phone', 'type' => 'Text', 'attributes' => array('id' => 'epf-phone', 'style' => 'width: 235px;'), 'options' => array('notes' => 'We only use this to inform you<br>about changes to your bookings'))); $this->add(array('name' => 'epf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Update phone number', 'class' => 'default-button'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('epf-phone' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your phone number here'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'This phone number is somewhat short ...')), array('name' => 'Regex', 'options' => array('pattern' => '/^([ \\+\\/\\(\\)\\-0-9])+$/u', 'message' => 'This phone number contains invalid characters - sorry'))))))); }
public function getInputFilter() { if (!$this->filter) { $factory = new InputFilterFactory(); $inputFilterSpec = array('type' => 'Dots\\InputFilter\\InputFilter', 'id' => array('required' => false), 'title' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'alias' => array('required' => false, 'allow_empty' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim')), 'validators' => array(array('name' => 'Zend\\Validator\\Db\\NoRecordExists', 'options' => array('table' => 'pages', 'field' => 'alias', 'adapter' => \Dots\Registry::get('service_locator')->get('Zend\\Db\\Adapter\\Adapter'), 'exclude' => "id!='" . $this->data['id'] . "'")))), 'template' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'language' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim')))); $this->filter = $factory->createInputFilter($inputFilterSpec); } return $this->filter; }
public function init() { $this->setName('pf'); $this->add(array('name' => 'pf-email', 'type' => 'Text', 'attributes' => array('id' => 'pf-email', 'class' => 'autofocus', 'style' => 'width: 250px;'), 'options' => array('label' => 'Email address', 'label_attributes' => array('class' => 'symbolic symbolic-email', 'label_attributes' => array('class' => 'symbolic symbolic-email'))))); $this->add(array('name' => 'pf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Change password', 'class' => 'default-button', 'style' => 'width: 175px;'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('pf-email' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true), array('name' => 'EmailAddress')))))); }
public function getInputFilter() { if (!$this->filter) { $factory = new InputFilterFactory(); $inputFilterSpec = array('id' => array('required' => false), 'page_id' => array('required' => false), 'title' => array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'keywords' => array('required' => false, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'description' => array('required' => false, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'author' => array('required' => false, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'robots' => array('required' => false, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'copyright' => array('required' => false, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))), 'charset' => array('required' => false), 'expires_after' => array('required' => false)); $this->filter = $factory->createInputFilter($inputFilterSpec); } return $this->filter; }
public function filter($name, $data) { // maybe check if the function exists first $filterArray = $this->{'get' . ucfirst($name) . 'Filters'}(); $factory = new Factory(); $filter = $factory->createInputFilter($filterArray); $filter->setData(array($name => $data)); return $filter; }
/** * Initialize UserLogin form * * @return void */ public function init() { $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('login' => array('required' => true, 'validators' => array(array('name' => 'not_empty'))), 'password' => array('required' => true, 'validators' => array(array('name' => 'not_empty'))))); $this->setInputFilter($inputFilter); $this->add(new Element('login')); $this->add(new Element('password')); $this->add(new Element('redirect')); }
public function init() { $this->setName('bf'); $this->add(array('name' => 'bf-time-start', 'type' => 'Text', 'attributes' => array('id' => 'bf-time-start', 'style' => 'width: 80px;'), 'options' => array('label' => 'Time (Start)'))); $this->add(array('name' => 'bf-time-end', 'type' => 'Text', 'attributes' => array('id' => 'bf-time-end', 'style' => 'width: 80px;'), 'options' => array('label' => 'Time (End)'))); $this->add(array('name' => 'bf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'id' => 'bf-submit', 'class' => 'default-button', 'style' => 'width: 125px;'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('bf-time-start' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^[0-9]?[0-9]:[0-9][0-9]$/', 'message' => 'Please provide the time in format HH:MM')))), 'bf-time-end' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type something here'), 'break_chain_on_failure' => true), array('name' => 'Regex', 'options' => array('pattern' => '/^[0-9]?[0-9]:[0-9][0-9]$/', 'message' => 'Please provide the time in format HH:MM'))))))); }
public function getInputFilter() { if (!$this->filter) { $factory = new InputFilterFactory(); $inputFilterSpec = array(); $inputFilterSpec['content'] = array('required' => true, 'filters' => array(array('name' => 'Zend\\Filter\\StringTrim'))); $this->filter = $factory->createInputFilter($inputFilterSpec); } return $this->filter; }
public function init() { $this->setName('prf'); $this->add(array('name' => 'prf-pw1', 'type' => 'Password', 'attributes' => array('id' => 'prf-pw1', 'class' => 'autofocus', 'style' => 'width: 250px;'), 'options' => array('label' => 'New password', 'label_attributes' => array('class' => 'symbolic symbolic-pw'), 'notes' => 'Your password will be safely encrypted'))); $this->add(array('name' => 'prf-pw2', 'type' => 'Password', 'attributes' => array('id' => 'prf-pw2', 'style' => 'width: 250px;'), 'options' => array('label' => ' ', 'notes' => 'Please type your password again'))); $this->add(array('name' => 'prf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Change password', 'class' => 'default-button', 'style' => 'width: 175px;'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('prf-pw1' => array('validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your password'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 4, 'message' => 'Your new password should be at least %min% characters long')))), 'prf-pw2' => array('validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your password here'), 'break_chain_on_failure' => true), array('name' => 'Identical', 'options' => array('token' => 'prf-pw1', 'message' => array('Both passwords must be identical')))))))); }
public function init() { $this->setName('daf'); $this->add(array('name' => 'daf-why', 'type' => 'Text', 'attributes' => array('id' => 'daf-why', 'style' => 'width: 640px;'), 'options' => array('notes' => 'Were you not happy with our service? Please tell us why you leave. Thank you!'))); $this->add(array('name' => 'daf-pw-current', 'type' => 'Password', 'attributes' => array('id' => 'daf-pw-current', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Your current password'))); $this->add(array('name' => 'daf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Delete account', 'class' => 'default-button'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('daf-why' => array('required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'StripTags'))), 'daf-pw-current' => array('validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your password here'), 'break_chain_on_failure' => true)))))); }
public function createService(ServiceLocatorInterface $serviceLocator) { $inputFilterPluginManager = $serviceLocator->getServiceLocator()->get('InputFilterManager'); /** @var array $config */ $config = $serviceLocator->getServiceLocator()->get('Config'); $types = $config['zource_contact_fields']['company']; $inputFilterConfig = $this->createConfig($types); /** @var Factory $inputFilterFactory */ $inputFilterFactory = new Factory($inputFilterPluginManager); return $inputFilterFactory->createInputFilter($inputFilterConfig); }
public function init() { $this->setName('epf'); $this->add(array('name' => 'epf-pw-current', 'type' => 'Password', 'attributes' => array('id' => 'epf-pw-current', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Your current password'))); $this->add(array('name' => 'epf-pw1', 'type' => 'Password', 'attributes' => array('id' => 'epf-pw1', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Your new password'))); $this->add(array('name' => 'epf-pw2', 'type' => 'Password', 'attributes' => array('id' => 'epf-pw2', 'style' => 'width: 235px;'), 'options' => array('notes' => 'Please type your new password again<br>to prevent typing errors'))); $this->add(array('name' => 'epf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Update password', 'class' => 'default-button'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('epf-pw-current' => array('validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type your password here'), 'break_chain_on_failure' => true))), 'epf-pw1' => array('validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type a new password here'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 4, 'message' => 'Your new password should be at least %min% characters long')))), 'epf-pw2' => array('validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type a new password here'), 'break_chain_on_failure' => true), array('name' => 'Identical', 'options' => array('token' => 'epf-pw1', 'message' => array('Both passwords must be identical')))))))); }
/** * Constructor. * * @param \Traversable|array $config */ public function __construct(array $config, Factory $inputFilterFactory = null) { if (null === $inputFilterFactory) { $inputFilterFactory = new Factory(); } try { $this->inputFilter = $inputFilterFactory->createInputFilter($config); } catch (\Exception $e) { throw new Exception\CreateInputFilterException(sprintf("Error creating ZF2 InputFilter: [%s] %s", get_class($e), $e->getMessage())); } }
/** * Initialize Role form * * @return void */ public function init() { $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('name' => array('required' => true, 'validators' => array(array('name' => 'not_empty'))), 'description' => array('required' => false), 'permissions' => array('required' => false))); $this->setInputFilter($inputFilter); $name = new Element\Text('name'); $name->setLabel('Name')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('class', 'form-control')->setAttribute('id', 'name'); $this->add($name); $description = new Element\Text('description'); $description->setLabel('Description')->setLabelAttributes(array('class' => 'optional control-label col-lg-2'))->setAttribute('class', 'form-control')->setAttribute('id', 'description'); $this->add($description); }
public function populateForm() { $this->form->add(new Element('foo')); $this->form->add(new Element('bar')); $fieldset = new Fieldset('foobar'); $fieldset->add(new Element('foo')); $fieldset->add(new Element('bar')); $this->form->add($fieldset); $inputFilterFactory = new InputFilterFactory(); $inputFilter = $inputFilterFactory->createInputFilter(array('foo' => array('name' => 'foo', 'required' => false, 'validators' => array(array('name' => 'not_empty'), array('name' => 'string_length', 'options' => array('min' => 3, 'max' => 5)))), 'bar' => array('allow_empty' => true, 'filters' => array(array('name' => 'string_trim'), array('name' => 'string_to_lower', 'options' => array('encoding' => 'ISO-8859-1')))), 'foobar' => array('type' => 'Zend\\InputFilter\\InputFilter', 'foo' => array('name' => 'foo', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'string_length', 'options' => array('min' => 3, 'max' => 5)))), 'bar' => array('allow_empty' => true, 'filters' => array(array('name' => 'string_trim'), array('name' => 'string_to_lower', 'options' => array('encoding' => 'ISO-8859-1'))))))); $this->form->setInputFilter($inputFilter); }
public function init() { $this->setName('cf'); $this->add(array('name' => 'cf-terms-file', 'type' => 'File', 'attributes' => array('id' => 'cf-terms-file', 'accept' => '.pdf'), 'options' => array('label' => 'Business terms (file)', 'notes' => 'Optional business terms as PDF-Document that must be accepted prior to registration'))); $this->add(array('name' => 'cf-terms-name', 'type' => 'Text', 'attributes' => array('id' => 'cf-terms-name', 'style' => 'width: 250px;'), 'options' => array('label' => 'Business terms (file name)', 'notes' => 'Optional file name of the PDF-Document above'))); $this->add(array('name' => 'cf-privacy-file', 'type' => 'File', 'attributes' => array('id' => 'cf-privacy-file', 'accept' => '.pdf'), 'options' => array('label' => 'Privacy policy (file)', 'notes' => 'Optional privacy policy as PDF-Document that must be accepted prior to registration'))); $this->add(array('name' => 'cf-privacy-name', 'type' => 'Text', 'attributes' => array('id' => 'cf-privacy-name', 'style' => 'width: 250px;'), 'options' => array('label' => 'Privacy policy (file name)', 'notes' => 'Optional file name of the PDF-Document above'))); $this->add(array('name' => 'cf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'class' => 'default-button', 'style' => 'width: 200px;'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('cf-terms-file' => array('required' => false, 'validators' => array(array('name' => 'File/MimeType', 'options' => array('mimeType' => 'application/pdf', 'message' => 'The selected file must be a PDF document file'), 'break_chain_on_failure' => true), array('name' => 'File/Size', 'options' => array('min' => '2kB', 'max' => '4MB', 'message' => 'The selected document\'s file size must be between 2 kB and 4 MB'), 'break_chain_on_failure' => true))), 'cf-terms-name' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'The name should be at least %min% characters long')))), 'cf-privacy-file' => array('required' => false, 'validators' => array(array('name' => 'File/MimeType', 'options' => array('mimeType' => 'application/pdf', 'message' => 'The selected file must be a PDF document file'), 'break_chain_on_failure' => true), array('name' => 'File/Size', 'options' => array('min' => '2kB', 'max' => '4MB', 'message' => 'The selected document\'s file size must be between 2 kB and 4 MB'), 'break_chain_on_failure' => true))), 'cf-privacy-name' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'The name should be at least %min% characters long'))))))); }
public function init() { $this->setName('uf'); $this->add(array('name' => 'uf-firstname', 'type' => 'Text', 'attributes' => array('id' => 'uf-firstname', 'style' => 'width: 250px;'), 'options' => array('label' => 'Firstname'))); $this->add(array('name' => 'uf-lastname', 'type' => 'Text', 'attributes' => array('id' => 'uf-lastname', 'style' => 'width: 250px;'), 'options' => array('label' => 'Lastname'))); $this->add(array('name' => 'uf-email', 'type' => 'Text', 'attributes' => array('id' => 'uf-email', 'style' => 'width: 250px;'), 'options' => array('label' => 'Email address', 'label_attributes' => array('class' => 'symbolic symbolic-email')))); $this->add(array('name' => 'uf-pw', 'type' => 'Password', 'attributes' => array('id' => 'uf-pw', 'style' => 'width: 250px;'), 'options' => array('label' => 'Password', 'label_attributes' => array('class' => 'symbolic symbolic-pw')))); $this->add(array('name' => 'uf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'class' => 'default-button', 'style' => 'width: 175px;'))); /* Input filters */ $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('uf-firstname' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Firstname should be at least %min% characters long')))), 'uf-lastname' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Lastname should be at least %min% characters long')))), 'uf-email' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'break_chain_on_failure' => true), array('name' => 'EmailAddress', 'options' => array('useMxCheck' => false, 'message' => 'Please type the correct email address here'), 'break_chain_on_failure' => true))), 'uf-pw' => array('validators' => array(array('name' => 'StringLength', 'options' => array('min' => 4, 'message' => 'The password should be at least %min% characters long'))))))); }
public function init() { $this->setName('euf'); /* Account data */ $this->add(array('name' => 'euf-uid', 'type' => 'Text', 'attributes' => array('id' => 'euf-uid', 'style' => 'width: 116px;', 'readonly' => true), 'options' => array('label' => 'No.'))); $this->add(array('name' => 'euf-alias', 'type' => 'Text', 'attributes' => array('id' => 'euf-alias', 'style' => 'width: 250px;'), 'options' => array('label' => 'Alias', 'notes' => 'Arbitrary name or identifier for this user'))); $this->add(array('name' => 'euf-status', 'type' => 'Select', 'attributes' => array('id' => 'euf-status', 'style' => 'width: 264px'), 'options' => array('label' => 'Status', 'value_options' => User::$statusOptions))); $this->add(array('name' => 'euf-privileges', 'type' => 'Select', 'attributes' => array('id' => 'euf-privileges', 'style' => 'width: 264px', 'multiple' => 'multiple', 'size' => count(User::$statusOptions)), 'options' => array('label' => 'Privileges', 'value_options' => User::$privileges, 'notes' => 'Press CTRL to select multiple items'))); $this->add(array('name' => 'euf-email', 'type' => 'Text', 'attributes' => array('id' => 'euf-email', 'style' => 'width: 250px;'), 'options' => array('label' => 'Email address'))); $this->add(array('name' => 'euf-pw', 'type' => 'Text', 'attributes' => array('id' => 'euf-pw', 'style' => 'width: 250px;'), 'options' => array('label' => 'New password'))); /* Personal data */ $this->add(array('name' => 'euf-gender', 'type' => 'Select', 'attributes' => array('id' => 'euf-gender'), 'options' => array('label' => 'Salutation', 'value_options' => array_merge(['-' => '-'], User::$genderOptions)))); $this->add(array('name' => 'euf-firstname', 'type' => 'Text', 'attributes' => array('id' => 'euf-firstname', 'style' => 'width: 116px;'), 'options' => array('label' => 'First & Last name'))); $this->add(array('name' => 'euf-lastname', 'type' => 'Text', 'attributes' => array('id' => 'euf-lastname', 'style' => 'width: 116px;'), 'options' => array('label' => 'Last name'))); $this->add(array('name' => 'euf-street', 'type' => 'Text', 'attributes' => array('id' => 'euf-street', 'style' => 'width: 250px;'), 'options' => array('label' => 'Street & Number'))); $this->add(array('name' => 'euf-zip', 'type' => 'Text', 'attributes' => array('id' => 'euf-zip', 'style' => 'width: 116px;'), 'options' => array('label' => 'Postal code & City'))); $this->add(array('name' => 'euf-city', 'type' => 'Text', 'attributes' => array('id' => 'euf-city', 'style' => 'width: 116px;'), 'options' => array('label' => 'City'))); $this->add(array('name' => 'euf-phone', 'type' => 'Text', 'attributes' => array('id' => 'euf-phone', 'style' => 'width: 250px;'), 'options' => array('label' => 'Phone number'))); $this->add(array('name' => 'euf-birthdate', 'type' => 'Text', 'attributes' => array('id' => 'euf-birthdate', 'style' => 'width: 116px;'), 'options' => array('label' => 'Birthday'))); $this->add(array('name' => 'euf-notes', 'type' => 'Textarea', 'attributes' => array('id' => 'euf-notes', 'style' => 'width: 250px; height: 48px;'), 'options' => array('label' => 'Notes', 'notes' => 'These are only visible for administration'))); $this->add(array('name' => 'euf-submit', 'type' => 'Submit', 'attributes' => array('value' => 'Save', 'class' => 'default-button', 'style' => 'width: 200px;'))); /* Input filters */ $userManager = $this->userManager; $that = $this; $factory = new Factory(); $this->setInputFilter($factory->createInputFilter(array('euf-uid' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'Digits', 'options' => array('message' => 'No. must be a number'), 'break_chain_on_failure' => true))), 'euf-alias' => array('filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type a name here'), 'break_chain_on_failure' => true), array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'The name should be at least %min% characters long')), array('name' => 'Callback', 'options' => array('callback' => function ($value) { return !is_numeric($value); }, 'message' => 'The name must not be a number')))), 'euf-privileges' => array('required' => false), 'euf-email' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'NotEmpty', 'options' => array('message' => 'Please type the email address here'), 'break_chain_on_failure' => true), array('name' => 'EmailAddress', 'options' => array('useMxCheck' => true, 'message' => 'Please type the correct email address here', 'messages' => array('emailAddressInvalidMxRecord' => 'Could not verify the email provider')), 'break_chain_on_failure' => true), array('name' => 'Callback', 'options' => array('callback' => function ($value) use($userManager, $that) { $uid = $that->get('euf-uid')->getValue(); if ($uid) { $user = $userManager->get($uid); } else { $user = null; } $usersWithEmail = $userManager->getBy(array('email' => $value, new IsNotNull('pw'))); if ($usersWithEmail) { $userWithEmail = current($usersWithEmail); if ($user) { if ($user->need('uid') == $userWithEmail->need('uid')) { return true; } } return false; } else { return true; } }, 'message' => 'This email address is already in use')))), 'euf-pw' => array('required' => false, 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 4, 'message' => 'The password should be at least %min% characters long')))), 'euf-firstname' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Firstname should be at least %min% characters long')))), 'euf-lastname' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Lastname should be at least %min% characters long')))), 'ef-street' => array('required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Callback', 'options' => array('callback' => function ($name) { return ucfirst($name); }))), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Street should be at least %min% characters long')))), 'euf-zip' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Postal code should be at least %min% characters long')))), 'euf-city' => array('required' => false, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'Callback', 'options' => array('callback' => function ($name) { return ucfirst($name); }))), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Postal code should be at least %min% characters long')))), 'euf-phone' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')), 'validators' => array(array('name' => 'StringLength', 'options' => array('min' => 3, 'message' => 'Phone number code should be at least %min% characters long')))), 'euf-birthdate' => array('required' => false, 'filters' => array(array('name' => 'StringTrim'))), 'euf-notes' => array('required' => false, 'filters' => array(array('name' => 'StringTrim')))))); }