From 48cbe43ded3790d334eccd91c590f7b0dcfad550 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Tue, 17 Jan 2012 11:17:35 +0100 Subject: [PATCH] MDL-31213 fix incorrect modifications of quickforms attributes --- lib/form/password.php | 9 +++++++-- lib/form/passwordunmask.php | 9 +++++++-- lib/formslib.php | 9 +++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/form/password.php b/lib/form/password.php index c157a47fad6..cfe1d7544df 100644 --- a/lib/form/password.php +++ b/lib/form/password.php @@ -19,9 +19,14 @@ class MoodleQuickForm_password extends HTML_QuickForm_password{ if (empty($CFG->xmlstrictheaders)) { // no standard mform in moodle should allow autocomplete of passwords // this is valid attribute in html5, sorry, we have to ignore validation errors in legacy xhtml 1.0 - $attributes = (array)$attributes; - if (!isset($attributes['autocomplete'])) { + if (empty($attributes)) { + $attributes = array('autocomplete'=>'off'); + } else if (is_array($attributes)) { $attributes['autocomplete'] = 'off'; + } else { + if (strpos($attributes, 'autocomplete') === false) { + $attributes .= ' autocomplete="off" '; + } } } diff --git a/lib/form/passwordunmask.php b/lib/form/passwordunmask.php index 7210323536e..40e087e1fd6 100644 --- a/lib/form/passwordunmask.php +++ b/lib/form/passwordunmask.php @@ -19,9 +19,14 @@ class MoodleQuickForm_passwordunmask extends MoodleQuickForm_password { if (empty($CFG->xmlstrictheaders)) { // no standard mform in moodle should allow autocomplete of passwords // this is valid attribute in html5, sorry, we have to ignore validation errors in legacy xhtml 1.0 - $attributes = (array)$attributes; - if (!isset($attributes['autocomplete'])) { + if (empty($attributes)) { + $attributes = array('autocomplete'=>'off'); + } else if (is_array($attributes)) { $attributes['autocomplete'] = 'off'; + } else { + if (strpos($attributes, 'autocomplete') === false) { + $attributes .= ' autocomplete="off" '; + } } } parent::MoodleQuickForm_password($elementName, $elementLabel, $attributes); diff --git a/lib/formslib.php b/lib/formslib.php index e816da60b56..003e1211017 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -143,9 +143,14 @@ abstract class moodleform { if (empty($CFG->xmlstrictheaders)) { // no standard mform in moodle should allow autocomplete with the exception of user signup // this is valid attribute in html5, sorry, we have to ignore validation errors in legacy xhtml 1.0 - $attributes = (array)$attributes; - if (!isset($attributes['autocomplete'])) { + if (empty($attributes)) { + $attributes = array('autocomplete'=>'off'); + } else if (is_array($attributes)) { $attributes['autocomplete'] = 'off'; + } else { + if (strpos($attributes, 'autocomplete') === false) { + $attributes .= ' autocomplete="off" '; + } } }