2006-09-24 17:04:51 +00:00
|
|
|
<?php
|
2012-01-06 16:38:06 +08:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Password type form element
|
|
|
|
*
|
|
|
|
* Contains HTML class for a password type element
|
|
|
|
*
|
|
|
|
* @package core_form
|
|
|
|
* @copyright 2006 Jamie Pratt <me@jamiep.org>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2006-09-24 17:04:51 +00:00
|
|
|
require_once('HTML/QuickForm/password.php');
|
2016-08-11 17:16:59 +08:00
|
|
|
require_once('templatable_form_element.php');
|
2006-09-24 17:04:51 +00:00
|
|
|
|
|
|
|
/**
|
2012-01-06 16:38:06 +08:00
|
|
|
* Password type form element
|
|
|
|
*
|
2006-09-24 17:04:51 +00:00
|
|
|
* HTML class for a password type element
|
2006-11-13 07:43:22 +00:00
|
|
|
*
|
2012-01-06 16:38:06 +08:00
|
|
|
* @package core_form
|
|
|
|
* @category form
|
|
|
|
* @copyright 2006 Jamie Pratt <me@jamiep.org>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
2006-09-24 17:04:51 +00:00
|
|
|
*/
|
MDL-55417 forms: Render form elements with a template
This change allows form elements to be overridden with a mustache template.
The template can even listen for form validation errors and supply the JS to
change the look of the form element when there is/isn't a validation error.
Initial support is for all core form elements including:
text, select, selectyesno and checkboxes, groups, dateselector, datetimeselector,
autocomplete, modvisible, advcheckbox, button, duration, filemanager, filepicker, editor, static, grading,
warning, textarea, password, url, submit, questioncategory, recaptcha.
Part of MDL-55071
2016-08-04 22:29:32 +08:00
|
|
|
class MoodleQuickForm_password extends HTML_QuickForm_password implements templatable {
|
2016-08-11 17:16:59 +08:00
|
|
|
use templatable_form_element;
|
|
|
|
|
2012-01-06 16:38:06 +08:00
|
|
|
/** @var string, html for help button, if empty then no help */
|
|
|
|
var $_helpbutton='';
|
|
|
|
|
2023-05-09 11:17:47 +07:00
|
|
|
/** @var bool if true label will be hidden. */
|
|
|
|
protected $_hiddenLabel = false;
|
|
|
|
|
2006-09-24 17:04:51 +00:00
|
|
|
/**
|
2012-01-06 16:38:06 +08:00
|
|
|
* constructor
|
2006-09-24 17:04:51 +00:00
|
|
|
*
|
2012-01-06 16:38:06 +08:00
|
|
|
* @param string $elementName (optional) name of the password element
|
|
|
|
* @param string $elementLabel (optional) label for password element
|
|
|
|
* @param mixed $attributes (optional) Either a typical HTML attribute string
|
|
|
|
* or an associative array
|
2006-09-24 17:04:51 +00:00
|
|
|
*/
|
2015-11-05 17:01:34 +08:00
|
|
|
public function __construct($elementName=null, $elementLabel=null, $attributes=null) {
|
2011-12-30 14:13:35 +01:00
|
|
|
global $CFG;
|
2022-12-06 12:28:27 +11:00
|
|
|
|
|
|
|
// No standard mform in moodle should allow autocomplete of passwords.
|
2012-07-21 19:23:44 +02:00
|
|
|
if (empty($attributes)) {
|
2022-12-06 12:28:27 +11:00
|
|
|
$attributes = ['autocomplete' => 'new-password'];
|
2021-06-23 13:47:21 +10:00
|
|
|
} else if (is_array($attributes) && empty($attributes['autocomplete'])) {
|
2022-12-06 12:28:27 +11:00
|
|
|
$attributes['autocomplete'] = 'new-password';
|
|
|
|
} else if (is_array($attributes) && $attributes['autocomplete'] === 'off') {
|
|
|
|
// A value of 'off' is ignored in all modern browsers and password
|
|
|
|
// managers and should be new-password instead.
|
|
|
|
$attributes['autocomplete'] = 'new-password';
|
2021-06-23 13:47:21 +10:00
|
|
|
} else if (is_string($attributes)) {
|
2012-07-21 19:23:44 +02:00
|
|
|
if (strpos($attributes, 'autocomplete') === false) {
|
2022-12-06 12:28:27 +11:00
|
|
|
$attributes .= ' autocomplete="new-password" ';
|
2011-12-30 14:13:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-05 17:01:34 +08:00
|
|
|
parent::__construct($elementName, $elementLabel, $attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Old syntax of class constructor. Deprecated in PHP7.
|
|
|
|
*
|
|
|
|
* @deprecated since Moodle 3.1
|
|
|
|
*/
|
|
|
|
public function MoodleQuickForm_password($elementName=null, $elementLabel=null, $attributes=null) {
|
|
|
|
debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER);
|
|
|
|
self::__construct($elementName, $elementLabel, $attributes);
|
2009-06-07 09:43:27 +00:00
|
|
|
}
|
2012-01-06 16:38:06 +08:00
|
|
|
|
2006-09-24 17:04:51 +00:00
|
|
|
/**
|
|
|
|
* get html for help button
|
|
|
|
*
|
2012-01-06 16:38:06 +08:00
|
|
|
* @return string html for help button
|
2006-09-24 17:04:51 +00:00
|
|
|
*/
|
|
|
|
function getHelpButton(){
|
|
|
|
return $this->_helpbutton;
|
|
|
|
}
|
2023-05-09 11:17:47 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets label to be hidden
|
|
|
|
*
|
|
|
|
* @param bool $hiddenLabel sets if label should be hidden
|
|
|
|
*/
|
|
|
|
public function setHiddenLabel($hiddenLabel) {
|
|
|
|
$this->_hiddenLabel = $hiddenLabel;
|
|
|
|
}
|
2006-09-24 17:04:51 +00:00
|
|
|
}
|