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" '; + } } }