From 84c053eca85f3372f3cd8941cf51103f4fbb2fd5 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 9 Mar 2026 10:27:08 +0000 Subject: [PATCH] MDL-88080 admin: initially focus the form element failing validation. This appears to replicate what the ancient admin_externalpage_print_header method did prior to being deprecated in db785816, however its replacement didn't support the same $focus argument - hence doing so manually now. --- admin/search.php | 5 ++--- admin/settings.php | 1 + admin/upgradesettings.php | 6 ++---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/admin/search.php b/admin/search.php index 2d1920d5ec1..d3e8c3f23d8 100644 --- a/admin/search.php +++ b/admin/search.php @@ -32,7 +32,6 @@ $adminroot = admin_get_root(); // need all settings here $adminroot->search = $query; // So we can reference it in search boxes later in this invocation $statusmsg = ''; $errormsg = ''; -$focus = ''; // now we'll deal with the case that the admin has submitted the form with changed settings if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and $data->action == 'save-settings') { @@ -41,7 +40,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and if (!empty($adminroot->errors)) { $errormsg = get_string('errorwithsettings', 'admin'); $firsterror = reset($adminroot->errors); - $focus = $firsterror->id; + $PAGE->set_focuscontrol($firsterror->id); } else { // No errors. Did we change any setting? If so, then redirect with success. if ($count) { @@ -55,7 +54,7 @@ $PAGE->set_primary_active_tab('siteadminnode'); // and finally, if we get here, then there are matching settings and we have to print a form // to modify them -echo $OUTPUT->header($focus); +echo $OUTPUT->header(); // Display a warning if site is not registered. if (empty($query)) { diff --git a/admin/settings.php b/admin/settings.php index 25ba9a556ac..7ff266d8f0b 100644 --- a/admin/settings.php +++ b/admin/settings.php @@ -72,6 +72,7 @@ if ($data = data_submitted() and confirm_sesskey() and isset($data->action) and } else { $errormsg = get_string('errorwithsettings', 'admin'); $firsterror = reset($adminroot->errors); + $PAGE->set_focuscontrol($firsterror->id); } $settingspage = $adminroot->locate($section, true); } diff --git a/admin/upgradesettings.php b/admin/upgradesettings.php index eecf91abbca..ae19b36eeff 100644 --- a/admin/upgradesettings.php +++ b/admin/upgradesettings.php @@ -35,8 +35,6 @@ if (isset($newsettings['frontpagesettings'])) { $newsettingshtml = implode($newsettings); unset($newsettings); -$focus = ''; - if (empty($adminroot->errors) and $newsettingshtml === '') { // there must be either redirect without message or continue button or else upgrade would be sometimes broken if ($return == 'site') { @@ -48,12 +46,12 @@ if (empty($adminroot->errors) and $newsettingshtml === '') { if (!empty($adminroot->errors)) { $firsterror = reset($adminroot->errors); - $focus = $firsterror->id; + $PAGE->set_focuscontrol($firsterror->id); } // and finally, if we get here, then there are new settings and we have to print a form // to modify them -echo $OUTPUT->header($focus); +echo $OUTPUT->header(); if (!empty($SITE->fullname) and !empty($SITE->shortname)) { echo $OUTPUT->box(get_string('upgradesettingsintro','admin'), 'generalbox');