Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 3.9.x will end* 10 May 2021 (12 months).
  • Bug fixes for security issues in 3.9.x will end* 8 May 2023 (36 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  
  18  /**
  19   * Button form element
  20   *
  21   * Contains HTML class for a button type element
  22   *
  23   * @package   core_form
  24   * @copyright 2007 Jamie Pratt <me@jamiep.org>
  25   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  26   */
  27  
  28  if (!defined('MOODLE_INTERNAL')) {
  29      die('Direct access to this script is forbidden.');    //  It must be included from a Moodle page
  30  }
  31  
  32  global $CFG;
  33  require_once($CFG->libdir.'/form/submit.php');
  34  
  35  /**
  36   * HTML class for a submit cancel type element
  37   *
  38   * Overloaded {@link MoodleQuickForm_submit} with default behavior modified to cancel a form.
  39   *
  40   * @package   core_form
  41   * @category  form
  42   * @copyright 2007 Jamie Pratt <me@jamiep.org>
  43   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  44   */
  45  class MoodleQuickForm_cancel extends MoodleQuickForm_submit
  46  {
  47      /**
  48       * constructor
  49       *
  50       * @param string $elementName (optional) name of the checkbox
  51       * @param string $value (optional) value for the button
  52       * @param mixed $attributes (optional) Either a typical HTML attribute string
  53       *              or an associative array
  54       */
  55      public function __construct($elementName=null, $value=null, $attributes=null)
  56      {
  57          if ($elementName==null){
  58              $elementName='cancel';
  59          }
  60          if ($value==null){
  61              $value=get_string('cancel');
  62          }
  63          parent::__construct($elementName, $value, $attributes);
  64          $this->updateAttributes(array('data-skip-validation' => 1, 'data-cancel' => 1,
  65              'onclick' => 'skipClientValidation = true; return true;'));
  66  
  67          // Add the class btn-cancel.
  68          $class = $this->getAttribute('class');
  69          if (empty($class)) {
  70              $class = '';
  71          }
  72          $this->updateAttributes(array('class' => $class . ' btn-cancel'));
  73      }
  74  
  75      /**
  76       * Old syntax of class constructor. Deprecated in PHP7.
  77       *
  78       * @deprecated since Moodle 3.1
  79       */
  80      public function MoodleQuickForm_cancel($elementName=null, $value=null, $attributes=null) {
  81          debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
  82          self::__construct($elementName, $value, $attributes);
  83      }
  84  
  85      /**
  86       * Called by HTML_QuickForm whenever form event is made on this element
  87       *
  88       * @param string $event Name of event
  89       * @param mixed $arg event arguments
  90       * @param object $caller calling object
  91       * @return bool
  92       */
  93      function onQuickFormEvent($event, $arg, &$caller)
  94      {
  95          switch ($event) {
  96              case 'createElement':
  97                  parent::onQuickFormEvent($event, $arg, $caller);
  98                  $caller->_registerCancelButton($this->getName());
  99                  return true;
 100                  break;
 101          }
 102          return parent::onQuickFormEvent($event, $arg, $caller);
 103      }
 104  
 105      /**
 106       * Returns the value of field without HTML tags
 107       *
 108       * @return string
 109       */
 110      function getFrozenHtml(){
 111          return HTML_QuickForm_submit::getFrozenHtml();
 112      }
 113  
 114  }