Example #1
0
 /**
  * Performs validation
  *
  * The whole rule chain is executed. Note that the side effect of this
  * method is setting the error message on element if validation fails
  *
  * @return   boolean     Whether the element is valid
  */
 public function validate()
 {
     $globalValid = false;
     $localValid = $this->checkValue($this->owner->getValue());
     foreach ($this->chainedRules as $item) {
         foreach ($item as $multiplier) {
             if (!$localValid) {
                 break;
             }
             $localValid = $localValid && $multiplier->validate();
         }
         $globalValid = $globalValid || $localValid;
         if ($globalValid) {
             break;
         }
         $localValid = true;
     }
     if (!$globalValid && strlen($this->message) && !$this->owner->getError()) {
         $this->owner->setError($this->message);
     }
     return $globalValid;
 }
Example #2
0
 /**
  * Renders a generic element
  *
  * @param HTML_QuickForm2_Node $element Element being rendered
  */
 public function renderElement(HTML_QuickForm2_Node $element)
 {
     if ($element->isRequired()) {
         $this->required = true;
     }
     if ($this->options['group_errors'] && ($error = $element->getError())) {
         $this->errors[$element->getId()] = $error;
     }
 }
Example #3
0
 /**
  * Creates an array with fields that are common to all elements
  *
  * @param    HTML_QuickForm2_Node    Element being rendered
  * @return   array
  */
 public function buildCommonFields(HTML_QuickForm2_Node $element)
 {
     $ary = array('id' => $element->getId(), 'frozen' => $element->toggleFrozen());
     if ($labels = $element->getLabel()) {
         if (!is_array($labels) || !$this->options['static_labels']) {
             $ary['label'] = $labels;
         } else {
             foreach ($labels as $key => $label) {
                 $key = is_int($key) ? $key + 1 : $key;
                 if (1 === $key) {
                     $ary['label'] = $label;
                 } else {
                     $ary['label_' . $key] = $label;
                 }
             }
         }
     }
     if (($error = $element->getError()) && $this->options['group_errors']) {
         $this->array['errors'][$ary['id']] = $error;
     } elseif ($error) {
         $ary['error'] = $error;
     }
     if (isset($this->styles[$ary['id']])) {
         $ary['style'] = $this->styles[$ary['id']];
     }
     if (!$element instanceof HTML_QuickForm2_Container) {
         $ary['html'] = $element->__toString();
     } else {
         $ary['elements'] = array();
         $ary['attributes'] = $element->getAttributes(true);
     }
     return $ary;
 }
Example #4
0
 /**
  * Processes the element's template, adding label(s), required note and error message
  *
  * @param    string                  Element template
  * @param    HTML_QuickForm2_Node    Element being rendered
  * @return   string  Template with some substitutions done
  */
 public function prepareTemplate($elTpl, HTML_QuickForm2_Node $element)
 {
     // if element is required
     $elTpl = $this->markRequired($elTpl, $element->isRequired());
     $elTpl = $this->outputError($elTpl, $element->getError());
     return $this->outputLabel($elTpl, $element->getLabel());
 }
Example #5
0
 /**
  * Sets the error message on the owner element
  */
 protected function setOwnerError()
 {
     if (strlen($this->getMessage()) && !$this->owner->getError()) {
         $this->owner->setError($this->getMessage());
     }
 }
Example #6
0
 public function renderHidden(HTML_QuickForm2_Node $element)
 {
     if ($err = $element->getError()) {
         $this->errors[] = $err;
     }
     return parent::renderHidden($element);
 }
Example #7
0
 /**
  * Creates an array with fields that are common to all elements
  *
  * @param    HTML_QuickForm2_Node    Element being rendered
  *
  * @return   array
  */
 public function buildCommonFields(HTML_QuickForm2_Node $element)
 {
     $keyn = $this->options['key_id'] ? 'id' : 'name';
     $ary = array('id' => $element->getId(), 'frozen' => $element->toggleFrozen(), 'name' => $element->getName());
     // Key that we use for putting into arrays so that smarty can extract them.
     // Note that the name may be empty.
     $key_val = $ary[$keyn];
     if ($key_val == '') {
         $key_val = $ary['id'];
     }
     if ($labels = $element->getLabel()) {
         if (!is_array($labels) || !$this->options['static_labels']) {
             $ary['label'] = $labels;
         } else {
             foreach ($labels as $key => $label) {
                 $key = is_int($key) ? $key + 1 : $key;
                 if (1 === $key) {
                     $ary['label'] = $label;
                 } else {
                     $ary['label_' . $key] = $label;
                 }
             }
         }
     }
     // Smarty: group_errors under 'name' or 'id' depending on key_id option:
     if (($error = $element->getError()) && $this->options['group_errors']) {
         $this->array['errors'][$key_val] = $error;
     } elseif ($error) {
         $ary['error'] = $error;
     }
     if (isset($this->styles[$key_val])) {
         $ary['style'] = $this->styles[$key_val];
     }
     if (!$element instanceof HTML_QuickForm2_Container) {
         $ary['html'] = $element->__toString();
     } else {
         $ary['elements'] = array();
         $ary['attributes'] = $element->getAttributes(true);
     }
     return $ary;
 }