-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMidTestForm.html
More file actions
167 lines (140 loc) · 5.02 KB
/
MidTestForm.html
File metadata and controls
167 lines (140 loc) · 5.02 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Formulir Kontak</title>
<style>
:root {
--primary-color: #279afe; /* Main button color */
--primary-hover-color: #1a7ed9; /* Button hover color */
--error-color: #ff4d4d; /* Error message color */
--border-color: #ccc; /* Input border color */
--input-bg: #f9f9f9; /* Input background color */
--font-color: #333; /* Main font color */
}
body {
font-family: 'Poppins', sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
form {
width: 100%;
max-width: 400px;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
color: var(--font-color);
margin-bottom: 20px;
}
label {
color: var(--font-color);
font-weight: 600;
margin-bottom: 8px;
display: block;
}
input, textarea {
width: 100%;
padding: 12px;
margin-bottom: 16px;
border: 1px solid var(--border-color);
border-radius: 4px;
box-sizing: border-box;
background-color: var(--input-bg);
font-size: 14px;
color: var(--font-color);
}
input:focus, textarea:focus {
border-color: var(--primary-color);
outline: none;
box-shadow: 0 0 5px var(--primary-color);
}
input[type="submit"] {
background-color: var(--primary-color);
color: #fff;
border: none;
padding: 12px;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s ease;
}
input[type="submit"]:hover {
background-color: var(--primary-hover-color);
}
.error {
color: var(--error-color);
font-size: 12px;
margin-top: -12px;
margin-bottom: 8px;
}
</style>
</head>
<body>
<form id="contactForm" onsubmit="return validateForm()">
<h2>Contact Form</h2>
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<div id="nameError" class="error"></div>
<label for="email">Email Address:</label>
<input type="text" id="email" name="email">
<div id="emailError" class="error"></div>
<label for="phone">Phone Number:</label>
<input type="text" id="phone" name="phone">
<div id="phoneError" class="error"></div>
<label for="message">Message:</label>
<textarea id="message" name="message" rows="4"></textarea>
<div id="messageError" class="error"></div>
<input type="submit" value="Submit">
</form>
<script>
function validateEmail(email) {
const re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
return re.test(String(email).toLowerCase());
}
function validateForm() {
let valid = true;
const name = document.getElementById('name').value.trim();
const email = document.getElementById('email').value.trim();
const phone = document.getElementById('phone').value.trim();
const message = document.getElementById('message').value.trim();
document.getElementById('nameError').innerHTML = '';
document.getElementById('emailError').innerHTML = '';
document.getElementById('phoneError').innerHTML = '';
document.getElementById('messageError').innerHTML = '';
if (name === "") {
document.getElementById('nameError').innerHTML = 'Please input your name';
valid = false;
}
if (email === "") {
document.getElementById('emailError').innerHTML = 'Please input your email address';
valid = false;
} else if (!validateEmail(email)) {
document.getElementById('emailError').innerHTML = 'Email format invalid';
valid = false;
}
if (phone === "") {
document.getElementById('phoneError').innerHTML = 'Please input your phone number';
valid = false;
}
if (message === "") {
document.getElementById('messageError').innerHTML = 'Please input your message';
valid = false;
}
if (valid) {
alert("Form has been submitted");
}
return valid;
}
</script>
</body>
</html>