web/lib/Zend/View/Helper/FormRadio.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_View
    16  * @package    Zend_View
    17  * @subpackage Helper
    17  * @subpackage Helper
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: FormRadio.php 20096 2010-01-06 02:05:09Z bkarwin $
    20  * @version    $Id: FormRadio.php 24865 2012-06-02 01:02:32Z adamlundrigan $
    21  */
    21  */
    22 
    22 
    23 
    23 
    24 /**
    24 /**
    25  * Abstract class for extension
    25  * Abstract class for extension
    31  * Helper to generate a set of radio button elements
    31  * Helper to generate a set of radio button elements
    32  *
    32  *
    33  * @category   Zend
    33  * @category   Zend
    34  * @package    Zend_View
    34  * @package    Zend_View
    35  * @subpackage Helper
    35  * @subpackage Helper
    36  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    36  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    37  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    38  */
    38  */
    39 class Zend_View_Helper_FormRadio extends Zend_View_Helper_FormElement
    39 class Zend_View_Helper_FormRadio extends Zend_View_Helper_FormElement
    40 {
    40 {
    41     /**
    41     /**
   121         }
   121         }
   122 
   122 
   123         // ensure value is an array to allow matching multiple times
   123         // ensure value is an array to allow matching multiple times
   124         $value = (array) $value;
   124         $value = (array) $value;
   125 
   125 
   126         // XHTML or HTML end tag?
   126         // Set up the filter - Alnum + hyphen + underscore
   127         $endTag = ' />';
   127         require_once 'Zend/Filter/PregReplace.php';
   128         if (($this->view instanceof Zend_View_Abstract) && !$this->view->doctype()->isXhtml()) {
   128         $pattern = @preg_match('/\pL/u', 'a') 
   129             $endTag= '>';
   129             ? '/[^\p{L}\p{N}\-\_]/u'    // Unicode
   130         }
   130             : '/[^a-zA-Z0-9\-\_]/';     // No Unicode
   131 
   131         $filter = new Zend_Filter_PregReplace($pattern, "");
       
   132         
   132         // add radio buttons to the list.
   133         // add radio buttons to the list.
   133         require_once 'Zend/Filter/Alnum.php';
       
   134         $filter = new Zend_Filter_Alnum();
       
   135         foreach ($options as $opt_value => $opt_label) {
   134         foreach ($options as $opt_value => $opt_label) {
   136 
   135 
   137             // Should the label be escaped?
   136             // Should the label be escaped?
   138             if ($escape) {
   137             if ($escape) {
   139                 $opt_label = $this->view->escape($opt_label);
   138                 $opt_label = $this->view->escape($opt_label);
   156             // generate ID
   155             // generate ID
   157             $optId = $id . '-' . $filter->filter($opt_value);
   156             $optId = $id . '-' . $filter->filter($opt_value);
   158 
   157 
   159             // Wrap the radios in labels
   158             // Wrap the radios in labels
   160             $radio = '<label'
   159             $radio = '<label'
   161                     . $this->_htmlAttribs($label_attribs) . ' for="' . $optId . '">'
   160                     . $this->_htmlAttribs($label_attribs) . '>'
   162                     . (('prepend' == $labelPlacement) ? $opt_label : '')
   161                     . (('prepend' == $labelPlacement) ? $opt_label : '')
   163                     . '<input type="' . $this->_inputType . '"'
   162                     . '<input type="' . $this->_inputType . '"'
   164                     . ' name="' . $name . '"'
   163                     . ' name="' . $name . '"'
   165                     . ' id="' . $optId . '"'
   164                     . ' id="' . $optId . '"'
   166                     . ' value="' . $this->view->escape($opt_value) . '"'
   165                     . ' value="' . $this->view->escape($opt_value) . '"'
   167                     . $checked
   166                     . $checked
   168                     . $disabled
   167                     . $disabled
   169                     . $this->_htmlAttribs($attribs)
   168                     . $this->_htmlAttribs($attribs)
   170                     . $endTag
   169                     . $this->getClosingBracket()
   171                     . (('append' == $labelPlacement) ? $opt_label : '')
   170                     . (('append' == $labelPlacement) ? $opt_label : '')
   172                     . '</label>';
   171                     . '</label>';
   173 
   172 
   174             // add to the array of radio buttons
   173             // add to the array of radio buttons
   175             $list[] = $radio;
   174             $list[] = $radio;
       
   175         }
       
   176         
       
   177         // XHTML or HTML for standard list separator?
       
   178         if (!$this->_isXhtml() && false !== strpos($listsep, '<br />')) {
       
   179             $listsep = str_replace('<br />', '<br>', $listsep);
   176         }
   180         }
   177 
   181 
   178         // done!
   182         // done!
   179         $xhtml .= implode($listsep, $list);
   183         $xhtml .= implode($listsep, $list);
   180 
   184