weekly release 3.1dev
[moodle.git] / lib / form / submit.php
CommitLineData
a23f0aaf 1<?php
6c1fd304
RT
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 * submit type form element
20 *
21 * Contains HTML class for a submit type element
22 *
23 * @package core_form
24 * @copyright 2006 Jamie Pratt <me@jamiep.org>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
27
a23f0aaf 28require_once("HTML/QuickForm/submit.php");
29
30/**
6c1fd304
RT
31 * submit type form element
32 *
a23f0aaf 33 * HTML class for a submit type element
34 *
6c1fd304
RT
35 * @package core_form
36 * @category form
37 * @copyright 2006 Jamie Pratt <me@jamiep.org>
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
a23f0aaf 39 */
40class MoodleQuickForm_submit extends HTML_QuickForm_submit {
6c1fd304
RT
41 /**
42 * constructor
43 *
44 * @param string $elementName (optional) name of the field
45 * @param string $value (optional) field label
46 * @param string $attributes (optional) Either a typical HTML attribute string or an associative array
47 */
3e8b394e 48 function MoodleQuickForm_submit($elementName=null, $value=null, $attributes=null) {
49 parent::HTML_QuickForm_submit($elementName, $value, $attributes);
50 }
6c1fd304 51
a23f0aaf 52 /**
53 * Called by HTML_QuickForm whenever form event is made on this element
54 *
6c1fd304
RT
55 * @param string $event Name of event
56 * @param mixed $arg event arguments
57 * @param object $caller calling object
a23f0aaf 58 */
59 function onQuickFormEvent($event, $arg, &$caller)
60 {
61 switch ($event) {
62 case 'createElement':
63 parent::onQuickFormEvent($event, $arg, $caller);
64 if ($caller->isNoSubmitButton($arg[0])){
65 //need this to bypass client validation
66 //for buttons that submit but do not process the
67 //whole form.
68 $onClick = $this->getAttribute('onclick');
69 $skip = 'skipClientValidation = true;';
70 $onClick = ($onClick !== null)?$skip.' '.$onClick:$skip;
71 $this->updateAttributes(array('onclick'=>$onClick));
72 }
73 return true;
74 break;
75 }
76 return parent::onQuickFormEvent($event, $arg, $caller);
77
6c1fd304
RT
78 }
79
64360ee7 80 /**
81 * Slightly different container template when frozen. Don't want to display a submit
82 * button if the form is frozen.
83 *
84 * @return string
85 */
86 function getElementTemplateType(){
87 if ($this->_flagFrozen){
88 return 'nodisplay';
89 } else {
95114b18 90 return 'actionbuttons';
64360ee7 91 }
92 }
4a0e2e63 93
6c1fd304
RT
94 /**
95 * Freeze the element so that only its value is returned
96 */
64360ee7 97 function freeze(){
98 $this->_flagFrozen = true;
99 }
4a0e2e63 100
a23f0aaf 101}