From 2c51a048f642c8ce0ff34d4e46b038a029e1ab56 Mon Sep 17 00:00:00 2001 From: Subhamoy Biswas Date: Sun, 10 Dec 2023 18:57:50 +0530 Subject: [PATCH] (feat): implemented basic form submission --- htdocs/assets/js/contactform-config.js | 34 +++++++++++++++++++++++--- htdocs/core/handle_contact.php | 29 ++++++++++++++++++++++ 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/htdocs/assets/js/contactform-config.js b/htdocs/assets/js/contactform-config.js index bc793da..110bee2 100644 --- a/htdocs/assets/js/contactform-config.js +++ b/htdocs/assets/js/contactform-config.js @@ -13,15 +13,43 @@ $(document).ready(function() { let name = nameInput.value; let email = emailInput.value; - let message = emailInput.value; + let message = messageInput.value; let recaptchaValue = grecaptcha.getResponse(); if(name !== "" && email !== "" && message !== "") { if(recaptchaValue !== "") { - + + let formData = { + name: name, + email: email, + message: message, + recaptcha: recaptchaValue + }; + + $(sendBtn).html("Sending...."); + $.ajax({ + url: 'core/handle_contact.php', + type: 'POST', + dataType: 'json', + contentType: 'application/json', + data: JSON.stringify(formData), + + success: function(response) { + if (response.alert && response.alertType) { + console.log(response.alert); + } + }, + error: function(jqXHR, textStatus, errorThrown) { + console.log(textStatus, errorThrown); + }, + complete: function() { + $(sendBtn).html("SEND "); + console.log("completed"); + } + }); } else { - show_alert("Please check-in reCaptcha", "info") + show_alert("Please check-in reCaptcha", "info"); } } else { diff --git a/htdocs/core/handle_contact.php b/htdocs/core/handle_contact.php index e69de29..b6bb565 100644 --- a/htdocs/core/handle_contact.php +++ b/htdocs/core/handle_contact.php @@ -0,0 +1,29 @@ + $alertMessage, "alertType" => $alertType)); + } +} + +?> \ No newline at end of file