HTML_QuickForm
[ class tree: HTML_QuickForm ] [ index: HTML_QuickForm ] [ all elements ]

Source for file radio.php

Documentation is available at radio.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group             |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
  17. // |          Bertrand Mansion <bmansion@mamasam.com>                     |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: radio.php,v 1.17 2004/02/28 22:10:16 avb Exp $
  21.  
  22. require_once('HTML/QuickForm/input.php');
  23.  
  24. /**
  25.  * HTML class for a radio type element
  26.  * 
  27.  * @author       Adam Daniel <adaniel1@eesus.jnj.com>
  28.  * @author       Bertrand Mansion <bmansion@mamasam.com>
  29.  * @version      1.1
  30.  * @since        PHP4.04pl1
  31.  * @access       public
  32.  */
  33. {
  34.     // {{{ properties
  35.  
  36.     /**
  37.      * Radio display text
  38.      * @var       string 
  39.      * @since     1.1
  40.      * @access    private
  41.      */
  42.     var $_text '';
  43.  
  44.     // }}}
  45.     // {{{ constructor
  46.  
  47.     /**
  48.      * Class constructor
  49.      * 
  50.      * @param     string    Input field name attribute
  51.      * @param     mixed     Label(s) for a field
  52.      * @param     string    Text to display near the radio
  53.      * @param     string    Input field value
  54.      * @param     mixed     Either a typical HTML attribute string or an associative array
  55.      * @since     1.0
  56.      * @access    public
  57.      * @return    void 
  58.      */
  59.     function HTML_QuickForm_radio($elementName=null$elementLabel=null$text=null$value=null$attributes=null)
  60.     {
  61.         $this->HTML_QuickForm_element($elementName$elementLabel$attributes);
  62.         if (isset($value)) {
  63.             $this->setValue($value);
  64.         }
  65.         $this->_persistantFreeze = true;
  66.         $this->setType('radio');
  67.         $this->_text $text;
  68.         $this->_generateId();
  69.     //end constructor
  70.     
  71.     // }}}
  72.     // {{{ setChecked()
  73.  
  74.     /**
  75.      * Sets whether radio button is checked
  76.      * 
  77.      * @param     bool    $checked  Whether the field is checked or not
  78.      * @since     1.0
  79.      * @access    public
  80.      * @return    void 
  81.      */
  82.     function setChecked($checked)
  83.     {
  84.         if (!$checked{
  85.             $this->removeAttribute('checked');
  86.         else {
  87.             $this->updateAttributes(array('checked'=>'checked'));
  88.         }
  89.     //end func setChecked
  90.  
  91.     // }}}
  92.     // {{{ getChecked()
  93.  
  94.     /**
  95.      * Returns whether radio button is checked
  96.      * 
  97.      * @since     1.0
  98.      * @access    public
  99.      * @return    string 
  100.      */
  101.     function getChecked()
  102.     {
  103.         return $this->getAttribute('checked');
  104.     //end func getChecked
  105.         
  106.     // }}}
  107.     // {{{ toHtml()
  108.  
  109.     /**
  110.      * Returns the radio element in HTML
  111.      * 
  112.      * @since     1.0
  113.      * @access    public
  114.      * @return    string 
  115.      */
  116.     function toHtml()
  117.     {
  118.         if (0 == strlen($this->_text)) {
  119.             $label '';
  120.         elseif ($this->_flagFrozen{
  121.             $label $this->_text;
  122.         else {
  123.             $label '<label for="' $this->getAttribute('id''">' $this->_text '</label>';
  124.         }
  125.         return HTML_QuickForm_input::toHtml($label;
  126.     //end func toHtml
  127.     
  128.     // }}}
  129.     // {{{ getFrozenHtml()
  130.  
  131.     /**
  132.      * Returns the value of field without HTML tags
  133.      * 
  134.      * @since     1.0
  135.      * @access    public
  136.      * @return    string 
  137.      */
  138.     function getFrozenHtml()
  139.     {
  140.         if ($this->getChecked()) {
  141.             return '<tt>(x)</tt>' .
  142.                    $this->_getPersistantData();
  143.         else {
  144.             return '<tt>( )</tt>';
  145.         }
  146.     //end func getFrozenHtml
  147.  
  148.     // }}}
  149.     // {{{ setText()
  150.  
  151.     /**
  152.      * Sets the radio text
  153.      * 
  154.      * @param     string    $text  Text to display near the radio button
  155.      * @since     1.1
  156.      * @access    public
  157.      * @return    void 
  158.      */
  159.     function setText($text)
  160.     {
  161.         $this->_text $text;
  162.     //end func setText
  163.  
  164.     // }}}
  165.     // {{{ getText()
  166.  
  167.     /**
  168.      * Returns the radio text
  169.      * 
  170.      * @since     1.1
  171.      * @access    public
  172.      * @return    string 
  173.      */
  174.     function getText()
  175.     {
  176.         return $this->_text;
  177.     //end func getText
  178.  
  179.     // }}}
  180.     // {{{ onQuickFormEvent()
  181.  
  182.     /**
  183.      * Called by HTML_QuickForm whenever form event is made on this element
  184.      *
  185.      * @param     string    $event  Name of event
  186.      * @param     mixed     $arg    event arguments
  187.      * @param     object    $caller calling object
  188.      * @since     1.0
  189.      * @access    public
  190.      * @return    void 
  191.      */
  192.     function onQuickFormEvent($event$arg&$caller)
  193.     {
  194.         switch ($event{
  195.             case 'updateValue':
  196.                 // constant values override both default and submitted ones
  197.                 // default values are overriden by submitted
  198.                 $value $this->_findValue($caller->_constantValues);
  199.                 if (null === $value{
  200.                     $value $this->_findValue($caller->_submitValues);
  201.                     if (null === $value{
  202.                         $value $this->_findValue($caller->_defaultValues);
  203.                     }
  204.                 }
  205.                 if ($value == $this->getValue()) {
  206.                     $this->setChecked(true);
  207.                 else {
  208.                     $this->setChecked(false);
  209.                 }
  210.                 break;
  211.             case 'setGroupValue':
  212.                 if ($arg == $this->getValue()) {
  213.                     $this->setChecked(true);
  214.                 else {
  215.                     $this->setChecked(false);
  216.                 }
  217.                 break;
  218.             default:
  219.                 parent::onQuickFormEvent($event$arg$caller);
  220.         }
  221.         return true;
  222.     // end func onQuickFormLoad
  223.  
  224.     // }}}
  225.     // {{{ exportValue()
  226.  
  227.    /**
  228.     * Returns the value attribute if the radio is checked, null if it is not
  229.     */
  230.     function exportValue(&$submitValues$assoc = false)
  231.     {
  232.         $value $this->_findValue($submitValues);
  233.         if (null === $value{
  234.             $value $this->getChecked()$this->getValue(): null;
  235.         elseif ($value != $this->getValue()) {
  236.             $value = null;
  237.         }
  238.         return $this->_prepareValue($value$assoc);
  239.     }
  240.     
  241.     // }}}
  242. //end class HTML_QuickForm_radio
  243. ?>

Documentation generated on Mon, 11 Mar 2019 14:16:36 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.