Skip to content

Commit 0b016ff

Browse files
committed
Add jQuery and update contact form submission
1 parent 8e9d462 commit 0b016ff

File tree

4 files changed

+53
-11
lines changed

4 files changed

+53
-11
lines changed

404.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
gtag("config", "G-CSN8G33F57");
4545
</script>
46+
<!-- jQuery -->
47+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
4648
</head>
4749

4850
<!-- Header -->
@@ -88,7 +90,12 @@
8890
<footer>
8991
<section class="contactform">
9092
<h1 class="Title">Get In Touch</h1>
91-
<form action="" method="post" name="contact-form">
93+
<form
94+
action="/contact.php"
95+
method="post"
96+
name="contact-form"
97+
id="contact-form"
98+
>
9299
<label for="name">Name:</label><br />
93100
<input
94101
type="text"

contact.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
if (isset($_POST["submit"])) {
32
// Only process POST requests
43
if ($_SERVER["REQUEST_METHOD"] == "POST") {
54
// Get form field values and sanitize them
@@ -46,5 +45,4 @@
4645
} else {
4746
// Not a POST request
4847
echo "Access Denied. You must use POST method to send data.";
49-
}
50-
}
48+
}

index.html

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
<link rel="stylesheet" type="text/css" href="portfolio.css" />
1515
<script src="portfolio.js" defer></script>
1616
<!-- Fonts and Icons -->
17-
<link
18-
rel="stylesheet"
19-
href="https://s.pageclip.co/v1/pageclip.css"
20-
media="screen"
21-
/>
2217
<link
2318
rel="stylesheet"
2419
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
@@ -47,6 +42,8 @@
4742

4843
gtag("config", "G-CSN8G33F57");
4944
</script>
45+
<!-- jQuery -->
46+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
5047
</head>
5148

5249
<!-- Header -->
@@ -612,7 +609,12 @@ <h1 class="Title" id="AltTitle">Projects</h1>
612609
<footer>
613610
<section class="contactform">
614611
<h1 class="Title">Get In Touch</h1>
615-
<form action="" method="post" name="contact-form">
612+
<form
613+
action="/contact.php"
614+
method="post"
615+
name="contact-form"
616+
id="contact-form"
617+
>
616618
<label for="name">Name:</label><br />
617619
<input
618620
type="text"

portfolio.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Make courses expandable
12
const courses = document.querySelectorAll(".Courses");
23

34
courses.forEach((course) => {
@@ -12,6 +13,7 @@ courses.forEach((course) => {
1213
});
1314
});
1415

16+
// Cards for projects
1517
const cardContainer = document.querySelector(".CardContainer");
1618

1719
// Fetch the JSON data
@@ -50,7 +52,7 @@ fetch("projects.json")
5052
});
5153
});
5254

53-
// Get all the navigation links
55+
// Make the navigation links active when the corresponding section is in the viewport
5456
const navLinks = document.querySelectorAll("nav a");
5557

5658
// Add a scroll event listener to the window
@@ -104,6 +106,7 @@ cards.forEach((card) => {
104106
}px`;
105107
});
106108

109+
// Search functionality for projects
107110
const searchInput = document.getElementById("searchInput");
108111
let debounceTimeout;
109112

@@ -171,6 +174,7 @@ function displayCards(data) {
171174
}
172175
}
173176

177+
// Skill search functionality
174178
const svgElements = document.querySelectorAll(".SkillCon");
175179

176180
svgElements.forEach((svg) => {
@@ -182,6 +186,7 @@ svgElements.forEach((svg) => {
182186
});
183187
});
184188

189+
// Function to trigger the search
185190
function triggerSearch(searchString) {
186191
// Fetch and filter data
187192
fetch("projects.json")
@@ -199,3 +204,33 @@ function triggerSearch(searchString) {
199204
displayCards(filteredData);
200205
});
201206
}
207+
208+
// Contact form submission
209+
$(document).ready(function () {
210+
// When the form is submitted
211+
$("#contact-form").on("submit", function (e) {
212+
// Prevent the default form submission
213+
e.preventDefault();
214+
215+
// Serialize the form data
216+
var formData = $(this).serialize();
217+
218+
// Send the form data to the server with AJAX
219+
$.ajax({
220+
type: "POST",
221+
url: "/contact.php",
222+
data: formData,
223+
success: function (response) {
224+
// Handle success (display success message, clear the form, etc.)
225+
alert(response);
226+
$("#contact-form").trigger("reset");
227+
},
228+
error: function () {
229+
// Handle error (display error message, etc.)
230+
alert(
231+
"There was an error sending your message. Please try again later."
232+
);
233+
},
234+
});
235+
});
236+
});

0 commit comments

Comments
 (0)