Exemple #1
0
 /**
  * Creates an array representing an element containing
  * the key for storing this
  *
  * @access private
  * @param  HTML_QuickForm_element    form element being visited
  * @param  bool                      Whether an element is required
  * @param  string                    Error associated with the element
  * @return array
  */
 function _elementToArray(&$element, $required, $error)
 {
     $ret = parent::_elementToArray($element, $required, $error);
     if ('group' == $ret['type']) {
         $ret['html'] = $element->toHtml();
         // we don't need the elements, see the array structure
         unset($ret['elements']);
     }
     if (($required || $error) && !empty($this->_required)) {
         $this->_renderRequired($ret['label'], $ret['html'], $required, $error);
     }
     if ($error && !empty($this->_error)) {
         $this->_renderError($ret['label'], $ret['html'], $error);
         $ret['error'] = $error;
     }
     // create keys for elements grouped by native group or name
     if (strstr($ret['name'], '[') or $this->_currentGroup) {
         // Fix for bug #8123: escape backslashes and quotes to prevent errors
         // in eval(). The code below seems to handle the case where element
         // name has unbalanced square brackets. Dunno whether we really
         // need this after the fix for #8123, but I'm wary of making big
         // changes to this code.
         preg_match('/([^]]*)\\[([^]]*)\\]/', $ret['name'], $matches);
         if (isset($matches[1])) {
             $sKeysSub = substr_replace($ret['name'], '', 0, strlen($matches[1]));
             $sKeysSub = str_replace(array('\\', '\'', '[', ']', '[\'\']'), array('\\\\', '\\\'', '[\'', '\']', '[]'), $sKeysSub);
             $sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $matches[1]) . '\']' . $sKeysSub;
         } else {
             $sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['name']) . '\']';
         }
         // special handling for elements in native groups
         if ($this->_currentGroup) {
             // skip unnamed group items unless radios: no name -> no static access
             // identification: have the same key string as the parent group
             if ($this->_currentGroup['keys'] == $sKeys and 'radio' != $ret['type']) {
                 return false;
             }
             // reduce string of keys by remove leading group keys
             if (0 === strpos($sKeys, $this->_currentGroup['keys'])) {
                 $sKeys = substr_replace($sKeys, '', 0, strlen($this->_currentGroup['keys']));
             }
         }
         // element without a name
     } elseif ($ret['name'] == '') {
         $sKeys = '[\'element_' . $this->_elementIdx . '\']';
         // other elements
     } else {
         $sKeys = '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['name']) . '\']';
     }
     // for radios: add extra key from value
     if ('radio' == $ret['type'] and substr($sKeys, -2) != '[]') {
         $sKeys .= '[\'' . str_replace(array('\\', '\''), array('\\\\', '\\\''), $ret['value']) . '\']';
     }
     $this->_elementIdx++;
     $ret['keys'] = $sKeys;
     return $ret;
 }
Exemple #2
0
 /**
  * Overrides method from parent class. Adds support for custom and plugin-custom
  * element types.
  *
  * @param  HTML_QuickForm_element    element being processed
  * @param  bool                      Whether an element is required
  * @param  string                    Error associated with the element
  * @return array representing an element
  */
 function _elementToArray(&$element, $required, $error)
 {
     $ret = parent::_elementToArray($element, $required, $error);
     //add id if any
     $elemId = $element->getAttribute('id');
     if (!empty($elemId)) {
         $ret['id'] = $elemId;
     }
     $type = $ret['type'];
     //add options from select
     if ('select' == $type) {
         $ret['selected'] = is_array($this->_values) ? array_map('strval', $this->_values) : array();
         foreach ($element->_options as $option) {
             $options[$option['attr']['value']] = $option['text'];
         }
         $ret['options'] = $options;
     }
     //add vars to array for custom
     if ('custom' == $type || 'plugin-custom' == $type || 'script' == $type || 'plugin-script' == $type) {
         $ret['vars'] = $element->getVars();
         $ret['templateId'] = $element->getTemplateId();
     }
     if ('custom' == $type || 'plugin-custom' == $type) {
         $ret['break'] = $element->isVisible();
     }
     if ('plugin-custom' == $type || 'plugin-script' == $type) {
         $ret['plugin'] = $element->getPluginName();
     }
     //decorators
     $decoratorsArr = $this->decoratorsToArray($element->getName());
     if ($decoratorsArr) {
         $ret['decorators'] = $decoratorsArr;
     }
     //add suport for label-placement
     $labelPlacement = $element->getAttribute("labelPlacement");
     if (!empty($labelPlacement)) {
         $ret['labelPlacement'] = $labelPlacement;
         $element->removeAttribute("labelPlacement");
     }
     //store all attributes so we can use them to generate html
     $ret['attributes'] = $element->getAttributes();
     return $ret;
 }
 /**
  * Creates an array representing an element containing
  * the key for storing this
  *
  * @access private
  * @param  object    An HTML_QuickForm_element object
  * @param  bool      Whether an element is required
  * @param  string    Error associated with the element
  * @return array
  */
 function _elementToArray(&$element, $required, $error)
 {
     $ret = parent::_elementToArray($element, $required, $error);
     if ('group' == $ret['type']) {
         $ret['html'] = $element->toHtml();
         // we don't need the elements, see the array structure
         unset($ret['elements']);
     }
     if (!empty($this->_required)) {
         $this->_renderRequired($ret['label'], $ret['html'], $required, $error);
     }
     if (!empty($this->_error)) {
         $this->_renderError($ret['label'], $ret['html'], $error);
         $ret['error'] = $error;
     }
     // create keys for elements grouped by native group or name
     if (strstr($ret['name'], '[') or $this->_currentGroup) {
         preg_match('/([^]]*)\\[([^]]*)\\]/', $ret['name'], $matches);
         if (isset($matches[1])) {
             $sKeysSub = substr_replace($ret['name'], '', 0, strlen($matches[1]));
             $sKeysSub = str_replace(array('[', ']', '[\'\']'), array('[\'', '\']', '[]'), $sKeysSub);
             $sKeys = '[\'' . $matches[1] . '\']' . $sKeysSub;
         } else {
             $sKeys = '[\'' . $ret['name'] . '\']';
         }
         // special handling for elements in native groups
         if ($this->_currentGroup) {
             // skip unnamed group items unless radios: no name -> no static access
             // identification: have the same key string as the parent group
             if ($this->_currentGroup['keys'] == $sKeys and 'radio' != $ret['type']) {
                 return false;
             }
             // reduce string of keys by remove leading group keys
             if (0 === strpos($sKeys, $this->_currentGroup['keys'])) {
                 $sKeys = substr_replace($sKeys, '', 0, strlen($this->_currentGroup['keys']));
             }
         }
         // element without a name
     } elseif ($ret['name'] == '') {
         $sKeys = '[\'element_' . $this->_elementIdx . '\']';
         // other elements
     } else {
         $sKeys = '[\'' . $ret['name'] . '\']';
     }
     // for radios: add extra key from value
     if ('radio' == $ret['type'] and substr($sKeys, -2) != '[]') {
         $sKeys .= '[\'' . $ret['value'] . '\']';
     }
     $this->_elementIdx++;
     $ret['keys'] = $sKeys;
     return $ret;
 }
Exemple #4
0
 function startForm(&$form)
 {
     parent::startForm($form);
     $this->_currentSection = 0;
     $this->_sectionCount = 1;
 }
Exemple #5
0
 function startForm(&$form)
 {
     parent::startForm($form);
     foreach ($form->_errors as $key => $val) {
         if (is_int($key)) {
             $this->_ary['errors'][] = $val;
         }
     }
 }
Exemple #6
0
 function startForm(&$form)
 {
     parent::startForm($form);
     foreach ($form->_errors as $key => $val) {
         if (is_int($key)) {
             $this->_ary['errors'][] = $val;
         }
     }
     if (method_exists($form, 'getSubmitLabel')) {
         $this->_ary['submit_label'] = $form->getSubmitLabel();
     }
 }