getElement(); if ((!$form instanceof Zend_Form) && (!$form instanceof Zend_Form_DisplayGroup)) { return $content; } $belongsTo = ($form instanceof Zend_Form) ? $form->getElementsBelongTo() : null; $elementContent = ''; $separator = $this->getSeparator(); $translator = $form->getTranslator(); $items = []; $view = $form->getView(); $class = $this->getOption('class'); foreach ($form as $item) { $item->setView($view) ->setTranslator($translator); if ($item instanceof Zend_Form_Element) { $item->setBelongsTo($belongsTo); } elseif (!empty($belongsTo) && ($item instanceof Zend_Form)) { if ($item->isArray()) { $name = $this->mergeBelongsTo($belongsTo, $item->getElementsBelongTo()); $item->setElementsBelongTo($name, true); } else { $item->setElementsBelongTo($belongsTo, true); } } elseif (!empty($belongsTo) && ($item instanceof Zend_Form_DisplayGroup)) { foreach ($item as $element) { $element->setBelongsTo($belongsTo); } } if ($item instanceof Zend_Form_Element) { $items[] = $this->_renderElement($item); } else if ($item instanceof Qs_Form) { $items[] = $this->_renderForm($item); } else { $items[] = $item->render(); } } $table = '' . implode($separator, $items) . '
'; switch ($this->getPlacement()) { case self::PREPEND: return $table . $separator . $content; case self::APPEND: default: return $content . $separator . $table; } } /** * @param $element Zend_Form_Element * @return string */ protected function _renderElement($element) { $class = get_class($element); $parts = explode('_', $class); $type = array_pop($parts); switch ($type) { case 'Checkbox': $value = $element->isChecked() ? '[X]' : '[X]'; break; case 'Radio': // the break was intentionally omitted case 'MultiCheckbox': $columns = (int) $element->getAttrib('columns'); $list = $element->getMultiOptions(); $values = $element->getValue(); if (null === $values) { $values = []; } else { $values = (array) $values; } foreach ($list as $i => &$optionValue) { if (in_array($i, $values)) { if ($type == 'Radio') { $optionValue = '(X) ' . htmlspecialchars($optionValue); } else { $optionValue = '[X] ' . htmlspecialchars($optionValue); } } else { if ($type == 'Radio') { $optionValue = '(X) ' . htmlspecialchars($optionValue); } else { $optionValue = '[X] ' . htmlspecialchars($optionValue); } } } $listsep = '
'; if ($columns > 1) { $value = ''; $count = count($list); $ipc = (int) ceil($count / $columns); for ($i = 0; $i < $columns; $i++) { $cellClass = 'cell-' . $i; if ($i == 0) { $cellClass = $cellClass . ' first'; } else if ($i == $columns - 1) { $cellClass = $cellClass . ' last'; } $value .= ''; } $value .= '
' . implode($listsep, array_slice($list, $i * $ipc, $ipc)) . '
'; } else { $value = implode($listsep, $list); } break; case 'Select': // the break was intentionally omitted case 'Multiselect': $_values = $element->getValue(); if (null === $_values) { $_values = []; } elseif (!is_array($_values)) { $_values = (array) $_values; } $value = []; foreach ($_values as $_value) { if (array_key_exists($_value, $element->options)) { $value[] = htmlspecialchars_decode(htmlspecialchars($element->options[$_value])); } } $value = implode('
', $value); break; case 'Textarea': $value = nl2br(htmlspecialchars($element->getValue())); break; case 'Password': $value = str_repeat('*', strlen($element->getValue())); break; case 'HtmlEditor': $value = $element->getValue(); break; case 'Date': if (false !== ($time = strtotime($element->getValue()))) { $value = date('m/d/Y', $time); } break; case 'Time': if (false !== ($time = strtotime($element->getValue()))) { $value = date($element->format, $time); } break; case 'MultiText': $_values = $element->getValue(); if (null === $_values) { $_values = []; } foreach ($_values as &$_value) { $_value = htmlspecialchars($_value); } $value = implode('
', $_values); break; default: $value = htmlspecialchars($element->getValue()); break; } $htmlBeforeElement = $htmlAfterElement = ''; /** @var Qs_Form_Decorator_ViewHelper $viewHelper */ if (($viewHelper = $element->getDecorator('ViewHelper'))) { $htmlAfterElement = $viewHelper->getHtmlAfterElement(); $htmlBeforeElement = $viewHelper->getHtmlBeforeElement(); } $content = '' . '' . $element->getLabel() . '' . '' . $htmlBeforeElement . $value . $htmlAfterElement . '' . ''; return $content; } protected function _renderForm($form) { $content = '' . '' . $form->getLegend() . '' . '' . $form->render() . '' . ''; $content1 = '' . '' . $form->render() . '' . ''; return $content; } }