HTML
<form action="https://falcon.warrensbox.com/your@email.com" method="POST">
<input type="text" name="contact_name">
<input type="email" name="contact_email">
<textarea name="message_content" rows="3"></textarea>
<input type="submit" value="Send">
</form>
JQuery
var $form = $('form#form-id'),
url = 'https://falcon.warrensbox.com/form'
$('#submit-form').on('click', function (e) {
e.preventDefault();
var form_values = $form.serializeObject()
//required
var config = { "owner_email":"your@email.com" }
$.extend(form_values,config)
$.ajax({
url: url,
method: "POST",
dataType: "json",
data: JSON.stringify(form_values)
}).success(
alert("Message Sent")
);
});
JavaScript
window.addEventListener("load", function () {
function getData() {
var formData = new FormData(form);
var XHR = new XMLHttpRequest();
var url = 'https://falcon.warrensbox.com/form'
var obj = {}
for (var data of formData.entries()) {
obj[data[0]] = data[1]
}
//required
obj["owner_email"] = "your@email.com"
XHR.addEventListener('load', function (event) {
alert('Message sent');
});
// Define what happens in case of error
XHR.addEventListener('error', function (event) {
alert('Unable to send message!');
});
XHR.open('POST', url);
XHR.send(JSON.stringify(obj));
}
var form = document.getElementById("myForm");
form.addEventListener("submit", function (event) {
event.preventDefault();
getData();
});
});