Example #1
0
 /**
  * Finishes rendering a form, called after processing contained elements
  *
  * @param    HTML_QuickForm2_Node    Form being rendered
  */
 public function finishForm(HTML_QuickForm2_Node $form)
 {
     $formTpl = str_replace(array('{attributes}', '{hidden}', '{errors}'), array($form->getAttributes(true), $this->hiddenHtml, $this->outputGroupedErrors()), $this->findTemplate($form, '{content}'));
     $this->hiddenHtml = '';
     // required note
     if (!$this->hasRequired || $form->toggleFrozen() || empty($this->options['required_note'])) {
         $formTpl = preg_replace('!<qf:reqnote>.*</qf:reqnote>!isU', '', $formTpl);
     } else {
         $formTpl = str_replace(array('<qf:reqnote>', '</qf:reqnote>', '{reqnote}'), array('', '', $this->options['required_note']), $formTpl);
     }
     $break = HTML_Common2::getOption('linebreak');
     $script = $this->getJavascriptBuilder()->getFormJavascript($form->getId());
     $this->html[0] = array(str_replace('{content}', $break . implode($break, $this->html[0]), $formTpl) . (empty($script) ? '' : $break . $script));
 }
Example #2
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 #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)
 {
     $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;
 }