feat: enhance quiz submit handling and hide back buttons

- Hide all buttons labeled 'Back' on document ready
- Add session key and attempt values logging to assist debugging
- Add AJAX request to finalize quiz attempts upon submission
- Ensure proper navigation or modal closure after quiz submission

These changes improve user experience by providing seamless form submission and debugging support.
This commit is contained in:
Kumi 2024-07-05 10:10:58 +02:00
parent b3b9ea55d1
commit 58993cbf51
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -53,6 +53,8 @@ document.addEventListener("DOMContentLoaded", function () {
.then(() => { .then(() => {
console.log("Bootstrap loaded successfully"); console.log("Bootstrap loaded successfully");
$(document).ready(function () { $(document).ready(function () {
$(".btn-secondary:contains('Back')").hide()
var embedded = getUrlParameter("embed"); var embedded = getUrlParameter("embed");
var inModal = getUrlParameter("modal"); var inModal = getUrlParameter("modal");
@ -94,18 +96,43 @@ document.addEventListener("DOMContentLoaded", function () {
encodeURIComponent(submitButton.val()); encodeURIComponent(submitButton.val());
} }
var sesskey = form.find('input[name=sesskey]').val();
var attempt = form.find('input[name=attempt]').val();
console.log(sesskey);
console.log(attempt);
// Perform the AJAX request // Perform the AJAX request
$.ajax({ $.ajax({
url: form.attr("action"), // Use the form's action attribute url: form.attr("action"), // Use the form's action attribute
type: form.attr("method"), // Use the form's method attribute type: form.attr("method"), // Use the form's method attribute
data: formData, data: formData,
success: function (response) { success: function (response) {
// Close the modal if `modal=1` is set if (form.attr("action").includes("/quiz/")) {
if (inModal === "1") { var finalize = "/mod/quiz/processattempt.php";
window.top.closeQuizModal(); var data = {
attempt: attempt,
finishattempt: 1,
sesskey: sesskey,
};
$.post(finalize, data, function (response) {
console.log(response);
// Close the modal if `modal=1` is set
if (inModal === "1") {
window.top.closeQuizModal();
} else {
// Else call the nextContent function
window.top.nextContent();
}
});
} else { } else {
// Else call the nextContent function // Close the modal if `modal=1` is set
window.top.nextContent(); if (inModal === "1") {
window.top.closeQuizModal();
} else {
// Else call the nextContent function
window.top.nextContent();
}
} }
}, },
error: function (xhr, status, error) { error: function (xhr, status, error) {