Skip to content
Permalink
9a92c88be1
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
108 lines (76 sloc) 3.06 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Contact Form</title>
</head>
<body>
<form onsubmit="return false"; action="https://formspree.io/mgezqgzj" method="POST" class="form" id='myForm' >
<input type="text" onkeyup="formBlur(this)" id="username" placeholder="Name" name="username">
<p id="p-user"></p>
<input type="subject" onkeyup="formBlur(this)" id="subject" placeholder="Subject" name="subject">
<p id="p-subject" ></p>
<input type="email" onkeyup="formBlur(this)" id="email" placeholder="Email" name="email">
<p id="p-email" ></p>
<textarea id="textarea" onkeyup="formBlur(this)" rows="4" cols="40" placeholder="message" name="message" ></textarea>
<p id="p-textarea"></p>
<button onclick="actionForm()" id="my-form-button" >Submit</button>
<p id="my-form-status"></p>
</form>
<script>
function actionForm()
{
var username = document.getElementById('username'),
subject = document.getElementById('subject'),
email = document.getElementById('email'),
textarea = document.getElementById('textarea');
if(username.value == "")
{
document.getElementById('p-user').textContent = "* Please input your name";
document.getElementById('username').style.border = "1px solid red";
}
if(subject.value == "")
{
document.getElementById('p-subject').textContent = "* Please input your subject";
document.getElementById('subject').style.border = "1px solid red";
}
if(email.value == "")
{
document.getElementById('p-email').textContent = "* Please input your email";
document.getElementById('email').style.border = "1px solid red";
}
if(textarea.value == "")
{
document.getElementById('p-textarea').textContent = "* Please input your message ";
document.getElementById('textarea').style.border = "1px solid red";
}
}
function formBlur(input)
{
if(input.value != '')
{
input.nextElementSibling.textContent = "";
input.style.border = '2px solid green';
}
}
const encodeFormData = (data) => {
return Object.keys(data)
.map(key => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
.join('&');
encodeFormData(formData);
};
const myForm = document.getElementById('myForm');
myForm.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
fetch("https://formspree.io/mgezqgzj", {
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-url-encoded', 'Accept': 'application/json'},
body: formData
})
.then(response => console.log(response))
.catch(error => console.log(error))
});
</script>
</body>
</html>