save($thesisId, $_POST, $_FILES); // Regenerate CSRF token after successful save $_SESSION['csrf_token'] = bin2hex(random_bytes(32)); App::flash('success', "TFE mis à jour avec succès!"); header('Location: ../edit.php?id=' . $thesisId); exit(); } catch (Exception $e) { error_log("Edit action error: " . $e->getMessage()); App::flash('error', $e->getMessage()); // WCAG 3.3.1 — map error message to field name for autofocus on re-render. $autofocusField = ThesisEditController::autofocusFieldForError($e->getMessage()); if ($autofocusField !== null) { App::flashAutofocus($autofocusField); } header('Location: ../edit.php?id=' . $thesisId); exit(); }