7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: FormErrors.php 16541 2009-07-07 06:59:03Z bkarwin $
24 * Abstract class for extension
26 require_once 'Zend/View/Helper/FormElement.php';
30 * Helper to render errors for a form element
35 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
36 * @license http://framework.zend.com/license/new-bsd New BSD License
38 class Zend_View_Helper_FormErrors
extends Zend_View_Helper_FormElement
41 * @var Zend_Form_Element
46 * @var string Element block start/end tags and separator
48 protected $_htmlElementEnd = '</li></ul>';
49 protected $_htmlElementStart = '<ul%s><li>';
50 protected $_htmlElementSeparator = '</li><li>';
56 * @param string|array $errors Error(s) to render
57 * @param array $options
60 public function formErrors($errors, array $options = null)
63 if (isset($options['escape'])) {
64 $escape = (bool) $options['escape'];
65 unset($options['escape']);
68 if (empty($options['class'])) {
69 $options['class'] = 'errors';
72 $start = $this->getElementStart();
73 if (strstr($start, '%s')) {
74 $attribs = $this->_htmlAttribs($options);
75 $start = sprintf($start, $attribs);
79 foreach ($errors as $key => $error) {
80 $errors[$key] = $this->view
->escape($error);
85 . implode($this->getElementSeparator(), (array) $errors)
86 . $this->getElementEnd();
92 * Set end string for displaying errors
94 * @param string $string
95 * @return Zend_View_Helper_FormErrors
97 public function setElementEnd($string)
99 $this->_htmlElementEnd
= (string) $string;
104 * Retrieve end string for displaying errors
108 public function getElementEnd()
110 return $this->_htmlElementEnd
;
114 * Set separator string for displaying errors
116 * @param string $string
117 * @return Zend_View_Helper_FormErrors
119 public function setElementSeparator($string)
121 $this->_htmlElementSeparator
= (string) $string;
126 * Retrieve separator string for displaying errors
130 public function getElementSeparator()
132 return $this->_htmlElementSeparator
;
136 * Set start string for displaying errors
138 * @param string $string
139 * @return Zend_View_Helper_FormErrors
141 public function setElementStart($string)
143 $this->_htmlElementStart
= (string) $string;
148 * Retrieve start string for displaying errors
152 public function getElementStart()
154 return $this->_htmlElementStart
;