diff --git a/form.php b/form.php index 92cd86c..e5a7815 100644 --- a/form.php +++ b/form.php @@ -212,6 +212,21 @@ class form $res .= $csrf->displayFormCSRF (); } + // Manage the focus. On the first visible element if there is no error, on + // the first error fields when there is one + foreach ($this->fields as $field) + { + if ($field->type !== "hidden") + break; + } + $focusElement = $field->name; + if (count ($errors) > 0) + { + reset ($errors); + $focusElement = key ($errors); + } + $res .= "\n"; $res .= "\n"; return $res; }