-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact_form.html
116 lines (102 loc) · 5.05 KB
/
contact_form.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Contact Form</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css">
<link rel="stylesheet" href="https://kit.fontawesome.com/2df9982f5a.css" crossorigin="anonymous">
<link rel="stylesheet" href="styles/contact.css">
<link rel="icon" href="images/title_logo.png" type="image/x-icon">
<link rel="stylesheet" href="styles/nav-style.css">
<link rel="stylesheet" href="styles/landing-page.css">
<link rel="stylesheet" href="styles/Root-HTML.css">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@emailjs/browser@4/dist/email.min.js"></script>
<script type="text/javascript">
(function() {
emailjs.init({
publicKey: "SVGG2rcl0GAtjc2D5",
});
})();
</script>
<script type="text/javascript">
window.onload = function() {
document.getElementById('contact-form').addEventListener('submit', function(event) {
event.preventDefault();
// Validate required fields
// Using trim() ensures that only meaningful input is considered during the validation process.
const emailID = document.getElementById('emailID').value.trim();
const username = document.getElementById('username').value.trim();
const query = document.getElementById('query').value.trim();
// If a user accidentally enters " " (just spaces) in the "Name" field, then:
// 1) Without trim(): The field would be considered filled, and the form would submit even though no meaningful data was provided.
// 2) With trim(): The field would be considered empty, and the form would not submit at all.
// This way, the user is notified about the required fields before submitting the form.
// Validate email format
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; // Email Regex pattern
if (!emailPattern.test(emailID)) {
alert('Please enter a valid email address');
return;
}
if (emailID === "" || username === "" || query === "") {
alert('Fields marked with * are mandatory');
return;
}
emailjs.sendForm('service_0z9ijp9', 'template_ng24h1n', this)
.then(() => {
alert('Thank you! Your message has been successfully sent!');
this.reset();
}, (error) => {
console.log('FAILED...', error);
});
});
}
</script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const mobileMenu = document.querySelector('.mobile-menu');
const nav = document.querySelector('nav');
mobileMenu.addEventListener('click', () => {
nav.classList.toggle('active');
});
});
</script>
</head>
<body>
<header>
<nav>
<div class="logo">
<img src="images/New-Logo.PNG" alt="Saket Khopkar's Logo">
</div>
<div class="nav-container">
<ul class="nav-links">
<li><a href="index.html">Home</a></li>
<li><a href="online.html">About Me</a></li>
<li><a href="team.html">Knowledge Base</a></li>
<li><a href="articles.html">Blog Posts</a></li>
<li><a href="contact_form.html">Contact</a></li>
</ul>
</div>
<div class="mobile-menu" aria-label="Mobile Menu">
<div class="line1"></div>
<div class="line2"></div>
<div class="line3"></div>
</div>
</nav>
</header>
<form id="contact-form" style="margin-top: 70px;">
<h4>Got any Queries? Ask Right Here</h4>
<label for="emailID">Email ID <span style="color: red;">*</span></label>
<input type="text" placeholder="Enter your Email ID" id="emailID" name="senderEmail" required>
<label for="username">Name <span style="color: red;">*</span></label>
<input type="text" placeholder="Enter your Name" id="username" name="senderName" required>
<label for="query">Your Query <span style="color: red;">*</span></label>
<input type="textarea" placeholder="Please elaborate your query" id="query" name="senderSubject" required>
<p style="text-align: center;">🌸🌸🌸🌸🌸🌸🌸🌸🌸</p>
<button type="submit">Send Message</button>
<br />
<button type="button" onclick="window.location.href='index.html'">Back to Home Page</button>
</form>
</body>
</html>