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(() => {
console.log("Bootstrap loaded successfully");
$(document).ready(function () {
$(".btn-secondary:contains('Back')").hide()
var embedded = getUrlParameter("embed");
var inModal = getUrlParameter("modal");
@ -94,18 +96,43 @@ document.addEventListener("DOMContentLoaded", function () {
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
$.ajax({
url: form.attr("action"), // Use the form's action attribute
type: form.attr("method"), // Use the form's method attribute
data: formData,
success: function (response) {
// Close the modal if `modal=1` is set
if (inModal === "1") {
window.top.closeQuizModal();
if (form.attr("action").includes("/quiz/")) {
var finalize = "/mod/quiz/processattempt.php";
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 call the nextContent function
window.top.nextContent();
// Close the modal if `modal=1` is set
if (inModal === "1") {
window.top.closeQuizModal();
} else {
// Else call the nextContent function
window.top.nextContent();
}
}
},
error: function (xhr, status, error) {