From 8b29aa2834e5fa19774db49118e086a4261deda1 Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Mon, 6 Nov 2017 00:50:41 +0100 Subject: [PATCH] Remove autocapitalize from login input boxes to avoid infringing HTML5 standard when non-Apple browsers --- main/auth/gotocourse.php | 18 ++++++++++++++-- main/inc/lib/api.lib.php | 32 ++++++++++++++++++++-------- main/inc/lib/template.lib.php | 39 +++++++++++++++++++++-------------- 3 files changed, 62 insertions(+), 27 deletions(-) diff --git a/main/auth/gotocourse.php b/main/auth/gotocourse.php index b6bace05a5..7afb047d2e 100755 --- a/main/auth/gotocourse.php +++ b/main/auth/gotocourse.php @@ -27,17 +27,31 @@ if (isset($_GET['firstpage'])) { $action = api_get_self().'?'.Security::remove_XSS($_SERVER['QUERY_STRING']); $action = str_replace('&', '&', $action); $form = new FormValidator('formLogin', 'post', $action, null, array('class'=>'form-stacked')); + $params = [ + 'placeholder' => get_lang('UserName') + ]; + // Avoid showing the autocapitalize option if the browser doesn't + // support it: this attribute is against the HTML5 standard + if (api_browser_support('autocapitalize')) { + $params['autocapitalize'] = 'none'; + } $form->addElement( 'text', 'login', null, - array('placeholder' => get_lang('UserName'), 'autocapitalize' => 'none') + $params ); + $params = [ + 'placeholder' => get_lang('Password') + ]; + if (api_browser_support('autocapitalize')) { + $params['autocapitalize'] = 'none'; + } $form->addElement( 'password', 'password', null, - array('placeholder' => get_lang('Password'), 'autocapitalize' => 'none') + $params ); $form->addButtonNext(get_lang('LoginEnter'), 'submitAuth'); // see same text in main_api.lib.php function api_not_allowed diff --git a/main/inc/lib/api.lib.php b/main/inc/lib/api.lib.php index 137a8eb3d5..98710ad8f9 100644 --- a/main/inc/lib/api.lib.php +++ b/main/inc/lib/api.lib.php @@ -3526,15 +3526,19 @@ function api_get_not_allowed_login_form() null, array('class' => 'form-stacked') ); + $params = [ + 'placeholder' => get_lang('UserName'), + 'class' => 'col-md-3' + ]; + if (api_browser_support('autocapitalize')) { + $params['autocapitalize'] = 'none'; + } + $form->addElement( 'text', 'login', null, - array( - 'autocapitalize' => 'none', - 'placeholder' => get_lang('UserName'), - 'class' => 'col-md-3' - ) + $params ); $form->addElement( 'password', @@ -6356,10 +6360,12 @@ function api_get_template($path_type = 'rel') } /** - * Check browser support for type files - * This function check if the users browser support a file format or - * return the current browser and major ver when $format=check_browser - * @param string $format + * Check browser support for specific file types or features + * This function checks if the user's browser supports a file format or given + * feature, or returns the current browser and major version when + * $format=check_browser. Only a limited number of formats and features are + * checked by this method. Make sure you check its definition first. + * @param string $format Can be a file format (extension like svg, webm, ...) or a feature (like autocapitalize, ...) * * @return bool or return text array if $format=check_browser * @author Juan Carlos RaƱa Trabado @@ -6537,6 +6543,14 @@ function api_browser_support($format = '') $result[$format] = false; return false; } + } elseif ($format == 'autocapitalize') { + // Help avoiding showing the autocapitalize option if the browser doesn't + // support it: this attribute is against the HTML5 standard + if ($current_browser == 'Safari' || $current_browser == 'iPhone') { + return true; + } else { + return false; + } } elseif ($format == "check_browser") { $array_check_browser = array($current_browser, $current_majorver); return $array_check_browser; diff --git a/main/inc/lib/template.lib.php b/main/inc/lib/template.lib.php index c2a032c24c..8268c6153a 100755 --- a/main/inc/lib/template.lib.php +++ b/main/inc/lib/template.lib.php @@ -1444,32 +1444,39 @@ class Template null, FormValidator::LAYOUT_BOX_NO_LABEL ); - + $params = [ + 'id' => 'login', + 'autofocus' => 'autofocus', + 'icon' => 'user fa-fw', + 'placeholder' => get_lang('UserName'), + ]; + $browserAutoCapitalize= false; + // Avoid showing the autocapitalize option if the browser doesn't + // support it: this attribute is against the HTML5 standard + if (api_browser_support('autocapitalize')) { + $browserAutoCapitalize = false; + $params['autocapitalize'] = 'none'; + } $form->addText( 'login', get_lang('UserName'), true, - array( - 'id' => 'login', - 'autofocus' => 'autofocus', - 'icon' => 'user fa-fw', - 'placeholder' => get_lang('UserName'), - 'autocapitalize' => 'none' - ) + $params ); - + $params = [ + 'id' => 'password', + 'icon' => 'lock fa-fw', + 'placeholder' => get_lang('Pass'), + ]; + if ($browserAutoCapitalize) { + $params['autocapitalize'] = 'none'; + } $form->addElement( 'password', 'password', get_lang('Pass'), - array( - 'id' => 'password', - 'icon' => 'lock fa-fw', - 'placeholder' => get_lang('Pass'), - 'autocapitalize' => 'none', - ) + $params ); - // Captcha $captcha = api_get_setting('allow_captcha'); $allowCaptcha = $captcha === 'true';