Added in contact section #12
219
dist/api/index.php
vendored
219
dist/api/index.php
vendored
@ -49,34 +49,207 @@ $app->get("/timelineData/{timeline}", function (Request $request, Response $resp
|
|||||||
$json = json_encode($result);
|
$json = json_encode($result);
|
||||||
|
|
||||||
$response->getBody()->write($json);
|
$response->getBody()->write($json);
|
||||||
return $response;
|
//if it is an error give a 404 code since it can't find the data
|
||||||
// //if it is an error give a 403 code since it can't find the data
|
if(array_key_exists("errorMessage", $result))
|
||||||
// if(array_key_exists("errorMessage", $result[-1]))
|
|
||||||
// {
|
|
||||||
// $response = $response->withStatus(403);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //use content type json to indicate json data on frontend.
|
|
||||||
// return $response->withHeader("Content-Type", "application/json");
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/projectData', function (Request $request, Response $response)
|
|
||||||
{
|
|
||||||
global $projectData;
|
|
||||||
|
|
||||||
$result= $projectData->getProjectData();
|
|
||||||
|
|
||||||
$json = json_encode($result);
|
|
||||||
|
|
||||||
$response->getBody()->write($json);
|
|
||||||
|
|
||||||
if(array_key_exists("errorMessage", $result[-1]))
|
|
||||||
{
|
{
|
||||||
$response = $response->withStatus(403);
|
$response = $response->withStatus(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
//use content type json to indicate json data on frontend.
|
//use content type json to indicate json data on frontend.
|
||||||
return $response->withHeader("Content-Type", "application/json");
|
return $response->withHeader("Content-Type", "application/json");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$app->get('/projectData', function (Request $request, Response $response)
|
||||||
|
{
|
||||||
|
global $projectData;
|
||||||
|
|
||||||
|
$result = $projectData->getProjectData();
|
||||||
|
|
||||||
|
$json = json_encode($result);
|
||||||
|
|
||||||
|
$response->getBody()->write($json);
|
||||||
|
|
||||||
|
if(array_key_exists("errorMessage", $result))
|
||||||
|
{
|
||||||
|
$response = $response->withStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
//use content type json to indicate json data on frontend.
|
||||||
|
return $response->withHeader("Content-Type", "application/json");
|
||||||
|
});
|
||||||
|
|
||||||
|
$app->post('/contact', function (Request $request, Response $response)
|
||||||
|
{
|
||||||
|
$data = $request->getParsedBody();
|
||||||
|
if(empty($data["fName"]) || empty($data["lName"]) || empty($data["email"]) || empty($data["subject"]) || empty($data["message"]))
|
||||||
|
{
|
||||||
|
$response->getBody()->write(json_encode(array("errorMessage" => "Please fill out all the fields")));
|
||||||
|
$response = $response->withStatus(400);
|
||||||
|
return $response->withHeader("Content-Type", "application/json");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!filter_var($data["email"], FILTER_VALIDATE_EMAIL))
|
||||||
|
{
|
||||||
|
$response->getBody()->write(json_encode(array("errorMessage" => "Email is not the correct format")));
|
||||||
|
$response = $response->withStatus(400);
|
||||||
|
return $response->withHeader("Content-Type", "application/json");
|
||||||
|
}
|
||||||
|
|
||||||
|
// email form filler/conatcter
|
||||||
|
$headers1 = "From: noreply@rohitpai.tech\r\n";
|
||||||
|
$headers1 .= "Reply-To: rohit@rohitpai.tech\r\n";
|
||||||
|
$headers1 .= "MIME-Version: 1.0\r\n";
|
||||||
|
$headers1 .= "Content-Type: text/html; charset=UTF-8\r\n";
|
||||||
|
|
||||||
|
$message1 = "
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{$data['subject']}</title>
|
||||||
|
<style>
|
||||||
|
@import url(\"https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,400;0,700;1,400;1,700&family=Share+Tech+Mono&family=Source+Sans+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900&display=swap\");
|
||||||
|
body {
|
||||||
|
font-family: Noto Sans KR, sans-serif;
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: var(--generalFS);
|
||||||
|
line-height: 1.625rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
table td, table th {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr:nth-child(even) {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
table th {
|
||||||
|
padding-top: 12px;
|
||||||
|
padding-bottom: 12px;
|
||||||
|
text-align: left;
|
||||||
|
background-color: hsla(79, 62%, 59%, 1);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
border-color: hsla(0, 0%, 78%, 1);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>Thank you for filling out the form on my website, I will try to respond to your query as soon as I can.</p>
|
||||||
|
<br>
|
||||||
|
<p>Below is what you filled in for your record</p>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<th>Firstname</th>
|
||||||
|
<th>Lastname</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Subject</th>
|
||||||
|
<th>message</th>
|
||||||
|
</thead>
|
||||||
|
<tr>
|
||||||
|
<td>{$data['fName']}</td>
|
||||||
|
<td>{$data['lName']}</td>
|
||||||
|
<td><a href=\"mailto:{$data['email']}\">{$data['email']}</a></td>
|
||||||
|
<td>{$data['subject']}</td>
|
||||||
|
<td>{$data['message']}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
<hr>
|
||||||
|
<p>Regards, <br> Rohit Pai <br> <a href=\"mailto:rohit@rohitpai.tech\">rohit@rohitpai.tech</a>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
";
|
||||||
|
|
||||||
|
mail($data["email"], $data["subject"], $message1, $headers1);
|
||||||
|
|
||||||
|
// email to me
|
||||||
|
$headers2 = "From: noreply@rohitpai.tech\r\n";
|
||||||
|
$headers2 .= "Reply-To: {$data['email']}\r\n";
|
||||||
|
$headers2 .= "MIME-Version: 1.0\r\n";
|
||||||
|
$headers2 .= "Content-Type: text/html; charset=UTF-8\r\n";
|
||||||
|
|
||||||
|
$message2 = "
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>{$data['subject']}</title>
|
||||||
|
<style>
|
||||||
|
@import url(\"https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,400;0,700;1,400;1,700&family=Share+Tech+Mono&family=Source+Sans+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900&display=swap\");
|
||||||
|
body {
|
||||||
|
font-family: Noto Sans KR, sans-serif;
|
||||||
|
font-style: normal;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: var(--generalFS);
|
||||||
|
line-height: 1.625rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border-collapse: collapse;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
table td, table th {
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr:nth-child(even) {
|
||||||
|
background-color: #f2f2f2;
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
table th {
|
||||||
|
padding-top: 12px;
|
||||||
|
padding-bottom: 12px;
|
||||||
|
text-align: left;
|
||||||
|
background-color: hsla(79, 62%, 59%, 1);
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
hr {
|
||||||
|
border-color: hsla(0, 0%, 78%, 1);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>{$data['fName']} {$data['lName']} filled in the form on the website, here is what they sent.</p>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<th>Firstname</th>
|
||||||
|
<th>Lastname</th>
|
||||||
|
<th>Email</th>
|
||||||
|
<th>Subject</th>
|
||||||
|
<th>message</th>
|
||||||
|
</thead>
|
||||||
|
<tr>
|
||||||
|
<td>{$data['fName']}</td>
|
||||||
|
<td>{$data['lName']}</td>
|
||||||
|
<td><a href=\"mailto:{$data['email']}\">{$data['email']}</a></td>
|
||||||
|
<td>{$data['subject']}</td>
|
||||||
|
<td>{$data['message']}</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
";
|
||||||
|
|
||||||
|
mail("rohit@rohitpai.tech", "{$data['fName']} {$data['lName']} filled in the form", $message2, $headers2);
|
||||||
|
return $response->withStatus(201);
|
||||||
|
});
|
||||||
|
|
||||||
$app->run();
|
$app->run();
|
4
dist/api/timelineData.php
vendored
4
dist/api/timelineData.php
vendored
@ -25,7 +25,7 @@ class timelineData
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return array(array("errorMessage" => "Error, edu data not found"));
|
return array("errorMessage" => "Error, edu data not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ class timelineData
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return array(array("errorMessage" => "Error, work data not found"));
|
return array("errorMessage" => "Error, work data not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
dist/css/main.css
vendored
2
dist/css/main.css
vendored
File diff suppressed because one or more lines are too long
2
dist/index.html
vendored
2
dist/index.html
vendored
File diff suppressed because one or more lines are too long
2
dist/js/main.js
vendored
2
dist/js/main.js
vendored
File diff suppressed because one or more lines are too long
28
gulpfile.js
28
gulpfile.js
@ -3,13 +3,6 @@ const browserSync = require("browser-sync").create();
|
|||||||
const htmlMin = require("gulp-htmlmin");
|
const htmlMin = require("gulp-htmlmin");
|
||||||
const cssMin = require("gulp-clean-css")
|
const cssMin = require("gulp-clean-css")
|
||||||
const terser = require("gulp-terser");
|
const terser = require("gulp-terser");
|
||||||
const ftp = require("vinyl-ftp");
|
|
||||||
const env = require("gulp-env");
|
|
||||||
|
|
||||||
/*env({
|
|
||||||
file: ".env",
|
|
||||||
type: ".ini"
|
|
||||||
});*/
|
|
||||||
|
|
||||||
const github = (process.env.github) ? true : false;
|
const github = (process.env.github) ? true : false;
|
||||||
|
|
||||||
@ -59,25 +52,6 @@ gulp.task("watchFiles", () =>
|
|||||||
gulp.watch("src/api/*.php", gulp.task("movePHPFiles"))
|
gulp.watch("src/api/*.php", gulp.task("movePHPFiles"))
|
||||||
});
|
});
|
||||||
|
|
||||||
/*gulp.task("ftp", () =>
|
|
||||||
{
|
|
||||||
let conn = ftp.create(
|
|
||||||
{
|
|
||||||
host: process.env.host,
|
|
||||||
user: process.env.user,
|
|
||||||
pass: process.env.pass,
|
|
||||||
parallel: 1,
|
|
||||||
});
|
|
||||||
return gulp.src("dist/**", {base: "dist", dot: true})
|
|
||||||
.pipe(conn.newerOrDifferentSize("/"))
|
|
||||||
.pipe(conn.dest("/"));
|
|
||||||
});*/
|
|
||||||
|
|
||||||
/*gulp.task("deploy", () =>
|
|
||||||
{
|
|
||||||
gulp.watch("dist", gulp.task("ftp"));
|
|
||||||
});*/
|
|
||||||
|
|
||||||
gulp.task("browserSync", () =>
|
gulp.task("browserSync", () =>
|
||||||
{
|
{
|
||||||
browserSync.init({
|
browserSync.init({
|
||||||
@ -99,7 +73,7 @@ gulp.task("default", async () =>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
(gulp.series("watchFiles", "browserSync")());
|
(gulp.series(gulp.parallel("watchFiles", "browserSync"))());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ $app->post('/contact', function (Request $request, Response $response)
|
|||||||
$headers1 .= "Content-Type: text/html; charset=UTF-8\r\n";
|
$headers1 .= "Content-Type: text/html; charset=UTF-8\r\n";
|
||||||
|
|
||||||
$message1 = "
|
$message1 = "
|
||||||
<html>
|
<html lang=\"en\">
|
||||||
<head>
|
<head>
|
||||||
<title>{$data['subject']}</title>
|
<title>{$data['subject']}</title>
|
||||||
<style>
|
<style>
|
||||||
@ -163,6 +163,7 @@ $app->post('/contact', function (Request $request, Response $response)
|
|||||||
<td>{$data['lName']}</td>
|
<td>{$data['lName']}</td>
|
||||||
<td><a href=\"mailto:{$data['email']}\">{$data['email']}</a></td>
|
<td><a href=\"mailto:{$data['email']}\">{$data['email']}</a></td>
|
||||||
<td>{$data['subject']}</td>
|
<td>{$data['subject']}</td>
|
||||||
|
<td>{$data['message']}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
<br>
|
<br>
|
||||||
@ -181,7 +182,7 @@ $app->post('/contact', function (Request $request, Response $response)
|
|||||||
$headers2 .= "Content-Type: text/html; charset=UTF-8\r\n";
|
$headers2 .= "Content-Type: text/html; charset=UTF-8\r\n";
|
||||||
|
|
||||||
$message2 = "
|
$message2 = "
|
||||||
<html>
|
<html lang=\"en\">
|
||||||
<head>
|
<head>
|
||||||
<title>{$data['subject']}</title>
|
<title>{$data['subject']}</title>
|
||||||
<style>
|
<style>
|
||||||
@ -226,7 +227,7 @@ $app->post('/contact', function (Request $request, Response $response)
|
|||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<p>{data['fName']} {data['lName']} filled in the form on the website, here is what they sent.</p>
|
<p>{$data['fName']} {$data['lName']} filled in the form on the website, here is what they sent.</p>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<th>Firstname</th>
|
<th>Firstname</th>
|
||||||
@ -240,6 +241,7 @@ $app->post('/contact', function (Request $request, Response $response)
|
|||||||
<td>{$data['lName']}</td>
|
<td>{$data['lName']}</td>
|
||||||
<td><a href=\"mailto:{$data['email']}\">{$data['email']}</a></td>
|
<td><a href=\"mailto:{$data['email']}\">{$data['email']}</a></td>
|
||||||
<td>{$data['subject']}</td>
|
<td>{$data['subject']}</td>
|
||||||
|
<td>{$data['message']}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
|
@ -63,7 +63,7 @@ div#sayHello #contactForm{
|
|||||||
#contactForm .flName {
|
#contactForm .flName {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
gap: 1;
|
gap: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#contactForm .formControl {
|
#contactForm .formControl {
|
||||||
@ -107,3 +107,105 @@ div#sayHello #contactForm{
|
|||||||
#contactForm .formControl input:not([type="submit"]) {
|
#contactForm .formControl input:not([type="submit"]) {
|
||||||
height: 3em;
|
height: 3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#contactForm .flName {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#contactForm .formControl {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#contactForm input[type="submit"] {
|
||||||
|
margin-top: 1em;
|
||||||
|
align-self: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
#contactForm .formControl input:not([type="submit"]), #contactForm .formControl textarea {
|
||||||
|
width: 100%;
|
||||||
|
border: 4px solid var(--primaryDefault);
|
||||||
|
background: none;
|
||||||
|
outline: none;
|
||||||
|
-webkit-border-radius: 1em;
|
||||||
|
-moz-border-radius: 1em;
|
||||||
|
border-radius: 0.5em;
|
||||||
|
padding: 0 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
#contactForm .formControl textarea {
|
||||||
|
padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#contactForm .formControl input:not([type="submit"]).invalid:invalid, #contactForm .formControl textarea.invalid:invalid {
|
||||||
|
border: 4px solid var(--errorDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
#contactForm .formControl input:not([type="submit"]).invalid:invalid:focus, #contactForm .formControl textarea.invalid:invalid:focus {
|
||||||
|
border: 4px solid var(--errorHover);
|
||||||
|
box-shadow: 0 4px 2px 0 var(--mutedBlack);
|
||||||
|
}
|
||||||
|
|
||||||
|
#contactForm .formControl input:not([type="submit"]):focus, #contactForm .formControl textarea:focus {
|
||||||
|
border: 4px solid var(--primaryHover);
|
||||||
|
}
|
||||||
|
|
||||||
|
#contactForm .formControl input:not([type="submit"]) {
|
||||||
|
height: 3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.message {
|
||||||
|
background: var(--primaryDefault);
|
||||||
|
color: #FFFFFF;
|
||||||
|
padding: 0.5em 0.8em;
|
||||||
|
-webkit-border-radius: 4px;
|
||||||
|
-moz-border-radius: 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
align-self: flex-start;
|
||||||
|
flex-direction: row-reverse;
|
||||||
|
position: relative;
|
||||||
|
height: 75px;
|
||||||
|
visibility: visible;
|
||||||
|
overflow: hidden;
|
||||||
|
-webkit-transition: all 0.5s ease-in-out;
|
||||||
|
-moz-transition: all 0.5s ease-in-out;
|
||||||
|
-ms-transition: all 0.5s ease-in-out;
|
||||||
|
-o-transition: all 0.5s ease-in-out;
|
||||||
|
transition: all 0.5s ease-in-out;
|
||||||
|
opacity: 1;
|
||||||
|
margin-top: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.message.error {
|
||||||
|
background: var(--errorDefault);
|
||||||
|
}
|
||||||
|
|
||||||
|
div.message button {
|
||||||
|
border: none;
|
||||||
|
background: none;
|
||||||
|
outline: none;
|
||||||
|
cursor: pointer;
|
||||||
|
color: #FFFFFF;
|
||||||
|
font-size: 1.25rem;
|
||||||
|
margin-top: -5px;
|
||||||
|
position: absolute;
|
||||||
|
transform: translate(0, 0);
|
||||||
|
transform-origin: 0 0;
|
||||||
|
right: 10px;
|
||||||
|
top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.message.hidden {
|
||||||
|
opacity: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
div.message button:hover {
|
||||||
|
text-shadow: -1px 2px var(--mutedBlack);
|
||||||
|
}
|
@ -18,7 +18,8 @@
|
|||||||
--primaryDefault: hsla(var(--mainHue), var(--mainSat), var(--mainLight), 1);
|
--primaryDefault: hsla(var(--mainHue), var(--mainSat), var(--mainLight), 1);
|
||||||
--primaryHover: hsla(var(--mainHue), var(--mainSat), calc(var(--mainLight) - 10%), 1);
|
--primaryHover: hsla(var(--mainHue), var(--mainSat), calc(var(--mainLight) - 10%), 1);
|
||||||
--timelineItemBrdr: hsla(var(--mainHue), var(--mainSat), calc(var(--mainLight) - 20%), 1);
|
--timelineItemBrdr: hsla(var(--mainHue), var(--mainSat), calc(var(--mainLight) - 20%), 1);
|
||||||
--errorDefault: hsla(0, var(--mainSat), var(--mainLight), 1);
|
--errorDefault: hsla(0, calc(var(--mainSat) + 10%),calc(var(--mainLight) + 10%), 1);
|
||||||
|
--errorHover: hsla(0, calc(var(--mainSat) + 10%), calc(var(--mainLight) - 10%), 1);
|
||||||
--grey: hsla(0, 0%, 39%, 1);
|
--grey: hsla(0, 0%, 39%, 1);
|
||||||
--notAvailableDefault: hsla(0, 0%, 39%, 1);
|
--notAvailableDefault: hsla(0, 0%, 39%, 1);
|
||||||
--notAvailableHover: hsla(0, 0%,32%, 1);
|
--notAvailableHover: hsla(0, 0%,32%, 1);
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
<title>Rohit Pai - Portfolio</title>
|
<title>Rohit Pai - Portfolio</title>
|
||||||
<link rel="stylesheet" href="css/main.css">
|
<link rel="stylesheet" href="css/main.css">
|
||||||
<script src="https://kit.fontawesome.com/ed3c25598e.js" crossorigin="anonymous"></script>
|
<script src="https://kit.fontawesome.com/ed3c25598e.js" crossorigin="anonymous"></script>
|
||||||
<script src="js/main.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
@ -122,28 +121,33 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="sayHello">
|
<div id="sayHello">
|
||||||
<h1>say hello</h1>
|
<h1>say hello</h1>
|
||||||
<form action="" id="contactForm">
|
<form action="" id="contactForm" method="POST">
|
||||||
<div class="flName">
|
<div class="flName">
|
||||||
<div class="formControl">
|
<div class="formControl">
|
||||||
<label for="fName">First Name</label>
|
<label for="fName">First Name</label>
|
||||||
<input type="text" name="fName" id="fName">
|
<input type="text" name="fName" id="fName" placeholder="John" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="formControl">
|
<div class="formControl">
|
||||||
<label for="lName">Last Name</label>
|
<label for="lName">Last Name</label>
|
||||||
<input type="text" name="lName" id="lName">
|
<input type="text" name="lName" id="lName" placeholder="Doe" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="formControl">
|
<div class="formControl">
|
||||||
<label for="email">Email</label>
|
<label for="email">Email</label>
|
||||||
<input type="email" id="email" name="email">
|
<input type="email" id="email" name="email" onchange="(this.value.length !== 0) ? this.classList.add('invalid') : this.classList.remove('invalid');" placeholder="john.doe@example.com" required>
|
||||||
</div>
|
</div>
|
||||||
<div class="formControl">
|
<div class="formControl">
|
||||||
<label for="subject">Subject</label>
|
<label for="subject">Subject</label>
|
||||||
<input type="text" name="subject" id="subject"/>
|
<input type="text" name="subject" id="subject" placeholder="Something very important..." required/>
|
||||||
</div>
|
</div>
|
||||||
<div class="formControl">
|
<div class="formControl">
|
||||||
<label for="message">Message</label>
|
<label for="message">Message</label>
|
||||||
<textarea name="message" id="message" cols="30" rows="10"></textarea></div>
|
<textarea name="message" id="message" cols="30" rows="10" placeholder="Heyyy!" required></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="message hidden" id="contactError">
|
||||||
|
<button class="close" type="button">×</button>
|
||||||
|
<div></div>
|
||||||
|
</div>
|
||||||
<input type="submit" class="btn btnPrimary boxShadowIn boxShadowOut" value="Say Hello">
|
<input type="submit" class="btn btnPrimary boxShadowIn boxShadowOut" value="Say Hello">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
@ -154,5 +158,6 @@
|
|||||||
<button class="goBackToTop"></button>
|
<button class="goBackToTop"></button>
|
||||||
</footer>
|
</footer>
|
||||||
</main>
|
</main>
|
||||||
|
<script src="js/main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -214,6 +214,10 @@ document.addEventListener('DOMContentLoaded', () =>
|
|||||||
getProjectData();
|
getProjectData();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// contact error message
|
||||||
|
document.querySelector("#contactError .close").addEventListener("click", () =>
|
||||||
|
document.querySelector("#contactError").classList.toggle("hidden"));
|
||||||
|
|
||||||
// contact form
|
// contact form
|
||||||
document.querySelector("#contactForm").addEventListener("submit", e =>
|
document.querySelector("#contactForm").addEventListener("submit", e =>
|
||||||
{
|
{
|
||||||
@ -225,60 +229,28 @@ document.querySelector("#contactForm").addEventListener("submit", e =>
|
|||||||
contactData.append("subject", document.querySelector("#subject").value);
|
contactData.append("subject", document.querySelector("#subject").value);
|
||||||
contactData.append("message", document.querySelector("#message").value);
|
contactData.append("message", document.querySelector("#message").value);
|
||||||
|
|
||||||
if (document.querySelector("#fName").value.length == 0)
|
const fields = ['#fName', '#lName', '#email', '#subject', '#message'];
|
||||||
{
|
let invalid = false;
|
||||||
document.querySelector("#fName").classList.add("invalid");
|
|
||||||
// please fill out all the fields
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
document.querySelector("#fName").classList.remove("invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.querySelector("#lName").value.length == 0)
|
fields.forEach(field => {
|
||||||
{
|
const element = document.querySelector(field);
|
||||||
document.querySelector("#lName").classList.add("invalid");
|
if (element.value.length === 0) {
|
||||||
// please fill out all the fields
|
element.classList.add("invalid");
|
||||||
return;
|
invalid = true;
|
||||||
}
|
} else {
|
||||||
else
|
element.classList.remove("invalid")
|
||||||
{
|
document.querySelector("#contactError").classList.remove("error");
|
||||||
document.querySelector("#lName").classList.remove("invalid");
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (document.querySelector("#email").value.length == 0)
|
if (invalid)
|
||||||
{
|
{
|
||||||
document.querySelector("#email").classList.add("invalid");
|
// show error message
|
||||||
// please fill out all the fields
|
document.querySelector("#contactError").classList.add("error");
|
||||||
|
document.querySelector("#contactError").classList.remove("hidden");
|
||||||
|
document.querySelector("#contactError div").innerText = "Please fill out all fields.";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
document.querySelector("#email").classList.remove("invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.querySelector("#subject").value.length == 0)
|
|
||||||
{
|
|
||||||
document.querySelector("#subject").classList.add("invalid");
|
|
||||||
// please fill out all the fields
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
document.querySelector("#subject").classList.remove("invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (document.querySelector("#message").value.length == 0)
|
|
||||||
{
|
|
||||||
document.querySelector("#message").classList.add("invalid");
|
|
||||||
// please fill out all the fields
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
document.querySelector("#message").classList.remove("invalid");
|
|
||||||
}
|
|
||||||
|
|
||||||
fetch("/api/contact",
|
fetch("/api/contact",
|
||||||
{
|
{
|
||||||
@ -288,8 +260,8 @@ document.querySelector("#contactForm").addEventListener("submit", e =>
|
|||||||
{
|
{
|
||||||
if(res.ok)
|
if(res.ok)
|
||||||
{
|
{
|
||||||
// show message box
|
document.querySelector("#contactError").classList.remove("hidden");
|
||||||
|
document.querySelector("#contactError div").innerText = "Thanks for contacting me, I will get back to you as soon as possible.";
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user