mirror of
https://github.com/neosubhamoy/neosubhamoy-portfolio.git
synced 2025-12-20 01:09:35 +05:30
(feat): implemented basic form submission
This commit is contained in:
@@ -13,15 +13,43 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
let name = nameInput.value;
|
let name = nameInput.value;
|
||||||
let email = emailInput.value;
|
let email = emailInput.value;
|
||||||
let message = emailInput.value;
|
let message = messageInput.value;
|
||||||
let recaptchaValue = grecaptcha.getResponse();
|
let recaptchaValue = grecaptcha.getResponse();
|
||||||
|
|
||||||
if(name !== "" && email !== "" && message !== "") {
|
if(name !== "" && email !== "" && message !== "") {
|
||||||
if(recaptchaValue !== "") {
|
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 <i class='fa-regular fa-paper-plane ml-2'></i>");
|
||||||
|
console.log("completed");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
show_alert("Please check-in reCaptcha", "info")
|
show_alert("Please check-in reCaptcha", "info");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
require '../../connection.php';
|
||||||
|
require 'query_functions.php';
|
||||||
|
|
||||||
|
function form_input_filter($conn, $data){
|
||||||
|
$data = trim($data);
|
||||||
|
$data = stripslashes($data);
|
||||||
|
$data = htmlspecialchars($data);
|
||||||
|
$data = mysqli_real_escape_string($conn, $data);
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
|
||||||
|
$jsonData = file_get_contents('php://input');
|
||||||
|
$formData = json_decode($jsonData, true);
|
||||||
|
|
||||||
|
$name = form_input_filter($conn, $formData['name']);
|
||||||
|
$email = form_input_filter($conn, $formData['email']);
|
||||||
|
$message = form_input_filter($conn, $formData['message']);
|
||||||
|
$recaptcha = form_input_filter($conn, $formData['recaptcha']);
|
||||||
|
|
||||||
|
$alertMessage = "Form Data Recived from ".$name;
|
||||||
|
$alertType = "success";
|
||||||
|
echo json_encode(array("alert" => $alertMessage, "alertType" => $alertType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Reference in New Issue
Block a user