2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
19 * submit type form element
21 * Contains HTML class for a submit type element
24 * @copyright 2006 Jamie Pratt <me@jamiep.org>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 require_once("HTML/QuickForm/submit.php");
29 require_once('templatable_form_element.php');
32 * submit type form element
34 * HTML class for a submit type element
38 * @copyright 2006 Jamie Pratt <me@jamiep.org>
39 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
41 class MoodleQuickForm_submit
extends HTML_QuickForm_submit
implements templatable
{
42 use templatable_form_element
{
43 export_for_template
as export_for_template_base
;
47 * @var bool $primary Is this button a primary button?
54 * @param string $elementName (optional) name of the field
55 * @param string $value (optional) field label
56 * @param string $attributes (optional) Either a typical HTML attribute string or an associative array
57 * @param bool|null $primary Is this button a primary button?
59 public function __construct($elementName=null, $value=null, $attributes=null, $primary = null) {
60 parent
::__construct($elementName, $value, $attributes);
62 // Fallback to legacy behaviour if no value specified.
63 if (is_null($primary)) {
64 $this->primary
= $this->getName() != 'cancel';
66 $this->primary
= $primary;
71 * Old syntax of class constructor. Deprecated in PHP7.
73 * @deprecated since Moodle 3.1
75 public function MoodleQuickForm_submit($elementName=null, $value=null, $attributes=null, $primary = null) {
76 debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER
);
77 self
::__construct($elementName, $value, $attributes, $primary);
81 * Called by HTML_QuickForm whenever form event is made on this element
83 * @param string $event Name of event
84 * @param mixed $arg event arguments
85 * @param object $caller calling object
87 function onQuickFormEvent($event, $arg, &$caller)
91 parent
::onQuickFormEvent($event, $arg, $caller);
92 if ($caller->isNoSubmitButton($arg[0])){
93 //need this to bypass client validation
94 //for buttons that submit but do not process the
96 $onClick = $this->getAttribute('onclick');
97 $skip = 'skipClientValidation = true;';
98 $onClick = ($onClick !== null)?
$skip.' '.$onClick:$skip;
99 $this->updateAttributes(array('onclick'=>$onClick));
104 return parent
::onQuickFormEvent($event, $arg, $caller);
109 * Slightly different container template when frozen. Don't want to display a submit
110 * button if the form is frozen.
114 function getElementTemplateType(){
115 if ($this->_flagFrozen
){
118 return 'actionbuttons';
123 * Freeze the element so that only its value is returned
126 $this->_flagFrozen
= true;
129 public function export_for_template(renderer_base
$output) {
130 $context = $this->export_for_template_base($output);
131 if (!$this->primary
) {
132 $context['secondary'] = true;