File indexing completed on 2025-03-02 05:29:58
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_View 0017 * @subpackage Helper 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @license http://framework.zend.com/license/new-bsd New BSD License 0020 * @version $Id$ 0021 */ 0022 0023 /** 0024 * Abstract class for extension 0025 */ 0026 // require_once 'Zend/View/Helper/FormElement.php'; 0027 0028 0029 /** 0030 * Helper to render errors for a form element 0031 * 0032 * @category Zend 0033 * @package Zend_View 0034 * @subpackage Helper 0035 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0036 * @license http://framework.zend.com/license/new-bsd New BSD License 0037 */ 0038 class Zend_View_Helper_FormErrors extends Zend_View_Helper_FormElement 0039 { 0040 /** 0041 * @var Zend_Form_Element 0042 */ 0043 protected $_element; 0044 0045 /**#@+ 0046 * @var string Element block start/end tags and separator 0047 */ 0048 protected $_htmlElementEnd = '</li></ul>'; 0049 protected $_htmlElementStart = '<ul%s><li>'; 0050 protected $_htmlElementSeparator = '</li><li>'; 0051 /**#@-*/ 0052 0053 /** 0054 * Render form errors 0055 * 0056 * @param string|array $errors Error(s) to render 0057 * @param array $options 0058 * @return string 0059 */ 0060 public function formErrors($errors, array $options = null) 0061 { 0062 $escape = true; 0063 if (isset($options['escape'])) { 0064 $escape = (bool) $options['escape']; 0065 unset($options['escape']); 0066 } 0067 0068 if (empty($options['class'])) { 0069 $options['class'] = 'errors'; 0070 } 0071 0072 if (isset($options['elementStart'])) { 0073 $this->setElementStart($options['elementStart']); 0074 } 0075 if (isset($options['elementEnd'])) { 0076 $this->setElementEnd($options['elementEnd']); 0077 } 0078 if (isset($options['elementSeparator'])) { 0079 $this->setElementSeparator($options['elementSeparator']); 0080 } 0081 0082 $start = $this->getElementStart(); 0083 if (strstr($start, '%s')) { 0084 $attribs = $this->_htmlAttribs($options); 0085 $start = sprintf($start, $attribs); 0086 } 0087 0088 if ($escape) { 0089 foreach ($errors as $key => $error) { 0090 $errors[$key] = $this->view->escape($error); 0091 } 0092 } 0093 0094 $html = $start 0095 . implode($this->getElementSeparator(), (array) $errors) 0096 . $this->getElementEnd(); 0097 0098 return $html; 0099 } 0100 0101 /** 0102 * Set end string for displaying errors 0103 * 0104 * @param string $string 0105 * @return Zend_View_Helper_FormErrors 0106 */ 0107 public function setElementEnd($string) 0108 { 0109 $this->_htmlElementEnd = (string) $string; 0110 return $this; 0111 } 0112 0113 /** 0114 * Retrieve end string for displaying errors 0115 * 0116 * @return string 0117 */ 0118 public function getElementEnd() 0119 { 0120 return $this->_htmlElementEnd; 0121 } 0122 0123 /** 0124 * Set separator string for displaying errors 0125 * 0126 * @param string $string 0127 * @return Zend_View_Helper_FormErrors 0128 */ 0129 public function setElementSeparator($string) 0130 { 0131 $this->_htmlElementSeparator = (string) $string; 0132 return $this; 0133 } 0134 0135 /** 0136 * Retrieve separator string for displaying errors 0137 * 0138 * @return string 0139 */ 0140 public function getElementSeparator() 0141 { 0142 return $this->_htmlElementSeparator; 0143 } 0144 0145 /** 0146 * Set start string for displaying errors 0147 * 0148 * @param string $string 0149 * @return Zend_View_Helper_FormErrors 0150 */ 0151 public function setElementStart($string) 0152 { 0153 $this->_htmlElementStart = (string) $string; 0154 return $this; 0155 } 0156 0157 /** 0158 * Retrieve start string for displaying errors 0159 * 0160 * @return string 0161 */ 0162 public function getElementStart() 0163 { 0164 return $this->_htmlElementStart; 0165 } 0166 0167 }