forked from rgfindl/serverless-contact-us-form
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontact.html
97 lines (94 loc) · 2.75 KB
/
contact.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
<!DOCTYPE html>
<html>
<head>
<title>Contact page</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://www.google.com/recaptcha/api.js"></script>
<script>
var endpointPostUrl = 'https://YOUR_SERVERLESS_ID.execute-api.eu-west-1.amazonaws.com/YOUR_STAGE';
function serializeFormJSON(form) {
var o = {};
var a = form.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
function onSubmitForm() {
var formData = JSON.stringify(serializeFormJSON($('#contact-us-form')));
console.log('formData');
console.log(formData);
$.ajax({
type: 'POST',
url: endpointPostUrl,
data: formData,
success: function(responseData) {
console.log('contactFormEndpoint answer: ', responseData);
// {"ResponseMetadata":{"RequestId":"2c1e4a51-6074-5b00-a6d1-1ea252987a7c"},"MessageId":"ba649ce7-f929-5ea8-babc-c814cbc56fd4"}
},
dataType: 'json',
contentType: 'application/json',
});
}
</script>
</head>
<body>
<h3>Contact us!</h3>
<form id="contact-us-form">
<div class="form-group">
<label for="contactUsFormName">Name</label>
<input
type="text"
id="contactUsFormName"
className="form-control"
name="name"
placeholder="Full name"
/>
</div>
<div class="form-group">
<label for="contactUsFormEmail">Email address</label>
<input
type="email"
id="contactUsFormEmail"
className="form-control"
name="email"
placeholder="Enter email"
/>
</div>
<div class="form-group">
<label for="contactUsFormPhone">Phone number</label>
<input
type="text"
id="contactUsFormPhone"
className="form-control"
name="phone"
placeholder="Enter phone"
/>
</div>
<div class="form-group">
<label for="contactUsFormMessage">Message</label>
<textarea
type="textarea"
id="contactUsFormMessage"
className="form-control"
name="message"
placeholder="Enter message"
></textarea>
</div>
<button
class="g-recaptcha"
data-sitekey="YOUR_RECAPTCHA_SITE_KEY"
data-callback="onSubmitForm"
>
Submit
</button>
</form>
</body>
</html>