Exemplo n.º 1
0
 /**
  * Attached the element's data filters to the filtrator object
  *
  * @param InputFilter $input
  *
  * @throws \InvalidArgumentException
  */
 protected function prepareFiltrator(InputFilter $input)
 {
     $filters = $this->getFilters();
     if (!$filters || !is_array($filters)) {
         return;
     }
     $filtrator = $input->getFiltrator();
     foreach ($filters as $filter) {
         $params = is_array($filter) ? $filter : array($filter);
         if (isset($params[0])) {
             $filtrator->add($this->getName(), $params[0], @$params[1], @$params[2], @$params[3]);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Adds the element's validation rules to the validator object
  *
  * @param InputFilter $input
  *
  * @throws \InvalidArgumentException
  */
 protected function prepareValidator(InputFilter $input)
 {
     $validationRules = $this->getValidationRules();
     if (!$validationRules || !is_array($validationRules)) {
         return;
     }
     $validator = $input->getValidator();
     foreach ($validationRules as $rule) {
         $params = (array) $rule;
         if (isset($params[0])) {
             $validator->add($this->getName(), $params[0], @$params[1], @$params[2], $this->getLabel());
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Renders a complete InputFilter object into a form
  * @param InputFilter $inputFilter
  * @return \Sirius\Html\Tag|string
  */
 public function render(InputFilter $inputFilter)
 {
     $inputFilter->prepare();
     // ensure it is prepare
     $props = $inputFilter->getAttributes();
     $treeBuilder = new TreeBuilder($inputFilter);
     $props = array_merge($props, $treeBuilder->getTree());
     return $this->make('widget-form', $props);
 }
Exemplo n.º 4
0
 /**
  * Attaches the upload handlers to the input object
  *
  * @param InputFilter $inputFilter
  */
 protected function prepareUploadHandlers(InputFilter $inputFilter)
 {
     $uploadValidator = new \Sirius\Validation\ValueValidator($inputFilter->getValidator()->getRuleFactory(), $inputFilter->getValidator()->getErroMessagePrototype(), $this->getLabel());
     // create the upload handler
     $uploadHandler = new Handler($this->getUploadContainer(), $this->getUploadOptions(), $uploadValidator);
     if (is_array($this->getUploadRules())) {
         foreach ($this->getUploadRules() as $rule) {
             if (!is_array($rule)) {
                 $rule = array($rule);
             }
             $name = $rule[0];
             $options = isset($rule[1]) ? $rule[1] : null;
             $message = isset($rule[2]) ? $rule[2] : null;
             $label = $this->getLabel();
             $uploadHandler->addRule($name, $options, $message, $label);
         }
     }
     $inputFilter->setUploadHandler($inputFilter->getUploadPrefix() . $this->getName(), $uploadHandler);
 }
Exemplo n.º 5
0
 public function init()
 {
     parent::init();
     $this->addElement('name', [Specs::LABEL => 'Your name', Specs::FILTERS => ['stringtrim'], Specs::VALIDATION => ['required']]);
     $this->addElement('email', [Specs::WIDGET => 'email', Specs::LABEL => 'Your email', Specs::FILTERS => ['stringtrim'], Specs::VALIDATION => ['required', 'email']]);
     $this->addElement('phone', [Specs::LABEL => 'Phone', Specs::FILTERS => ['stringtrim']]);
     $this->addElement('source', [Specs::LABEL => 'Where did you hear about us?', Specs::WIDGET => 'radioset', Specs::OPTIONS => ['search_engine' => 'Search engine (Google, Yahoo, Bing)', 'newsletter' => 'Newsletter', 'friend' => 'Friend', 'unknown' => 'Don\'t recall']]);
     $this->addElement('message', [Specs::WIDGET => 'textarea', Specs::LABEL => 'Message', Specs::HINT => 'Please be as explicit as possible', Specs::ATTRIBUTES => ['rows' => 5], Specs::FILTERS => ['stringtrim'], Specs::VALIDATION => ['required', ['minlength', ['min' => 10]]]]);
     $this->addElement('buttons', [Specs::TYPE => 'group']);
     $this->addElement('submit', [Specs::WIDGET => 'submit', Specs::LABEL => 'Send inquiry', Specs::GROUP => 'buttons']);
     $this->addElement('reset', [Specs::WIDGET => 'reset', Specs::LABEL => 'Reset', Specs::GROUP => 'buttons']);
 }