Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   1  <?php
   2  /* vim: set expandtab tabstop=4 shiftwidth=4: */
   3  // +----------------------------------------------------------------------+
   4  // | PHP Version 4                                                        |
   5  // +----------------------------------------------------------------------+
   6  // | Copyright (c) 1997-2003 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: Alexey Borzov <avb@php.net>                                 |
  17  // +----------------------------------------------------------------------+
  18  //
  19  // $Id$
  20  
  21  require_once 'HTML/QuickForm/element.php';
  22  
  23  /**
  24   * Class for HTML 4.0 <button> element
  25   * 
  26   * @author  Alexey Borzov <avb@php.net>
  27   * @since   3.2.3
  28   * @access  public
  29   */
  30  class HTML_QuickForm_xbutton extends HTML_QuickForm_element
  31  {
  32     /**
  33      * Contents of the <button> tag
  34      * @var      string
  35      * @access   private
  36      */
  37      var $_content; 
  38  
  39     /**
  40      * Class constructor
  41      * 
  42      * @param    string  Button name
  43      * @param    string  Button content (HTML to add between <button></button> tags)
  44      * @param    mixed   Either a typical HTML attribute string or an associative array
  45      * @access   public
  46      */
  47      public function __construct($elementName = null, $elementContent = null, $attributes = null) {
  48          parent::__construct($elementName, null, $attributes);
  49          $this->setContent($elementContent);
  50          $this->setPersistantFreeze(false);
  51          $this->_type = 'xbutton';
  52      }
  53  
  54      /**
  55       * Old syntax of class constructor. Deprecated in PHP7.
  56       *
  57       * @deprecated since Moodle 3.1
  58       */
  59      public function HTML_QuickForm_xbutton($elementName = null, $elementContent = null, $attributes = null) {
  60          debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
  61          self::__construct($elementName, $elementContent, $attributes);
  62      }
  63  
  64      function toHtml()
  65      {
  66          return '<button' . $this->getAttributes(true) . '>' . $this->_content . '</button>';
  67      }
  68  
  69  
  70      function getFrozenHtml()
  71      {
  72          return $this->toHtml();
  73      }
  74  
  75  
  76      function freeze()
  77      {
  78          return false;
  79      }
  80  
  81  
  82      function setName($name)
  83      {
  84          $this->updateAttributes(array(
  85              'name' => $name 
  86          ));
  87      }
  88  
  89  
  90      function getName()
  91      {
  92          return $this->getAttribute('name');
  93      }
  94  
  95  
  96      function setValue($value)
  97      {
  98          $this->updateAttributes(array(
  99              'value' => $value
 100          ));
 101      }
 102  
 103  
 104      function getValue()
 105      {
 106          return $this->getAttribute('value');
 107      }
 108  
 109  
 110     /**
 111      * Sets the contents of the button element
 112      *
 113      * @param    string  Button content (HTML to add between <button></button> tags)
 114      */
 115      function setContent($content)
 116      {
 117          $this->_content = $content;
 118      }
 119  
 120  
 121      function onQuickFormEvent($event, $arg, &$caller)
 122      {
 123          if ('updateValue' != $event) {
 124              return parent::onQuickFormEvent($event, $arg, $caller);
 125          } else {
 126              $value = $this->_findValue($caller->_constantValues);
 127              if (null === $value) {
 128                  $value = $this->_findValue($caller->_defaultValues);
 129              }
 130              if (null !== $value) {
 131                  $this->setValue($value);
 132              }
 133          }
 134          return true;
 135      }
 136  
 137  
 138     /**
 139      * Returns a 'safe' element's value
 140      * 
 141      * The value is only returned if the button's type is "submit" and if this
 142      * particlular button was clicked
 143      */
 144      function exportValue(&$submitValues, $assoc = false)
 145      {
 146          if ('submit' == $this->getAttribute('type')) {
 147              return $this->_prepareValue($this->_findValue($submitValues), $assoc);
 148          } else {
 149              return null;
 150          }
 151      }
 152  }
 153  ?>