1 let querystring = require('querystring')
2 let stream_buffers = require('stream-buffers')
3 let XDate = require('xdate')
6 let breadcrumbs = await _require('/_lib/breadcrumbs.jst')
7 let globals = await env.site.get_json('/_config/globals.json')
8 let navbar = await _require('/_lib/navbar.jst')
14 await breadcrumbs(env, _out)
16 if (env.request.method == 'POST') {
17 let write_stream = new stream_buffers.WritableStreamBuffer()
18 let data = new Promise(
19 (resolve, reject) => {
21 on('finish', () => {resolve(write_stream.getContents())}).
22 on('error', () => {reject()})
25 env.request.pipe(write_stream)
26 let query = querystring.parse((await data).toString())
27 console.log('received contact form:', query.email)
29 // save the form contents in a dated logfile, so that we can
30 // recover manually if the email doesn't send for some reason
32 query.date = date.toUTCString()
34 let transaction = await env.site.database.Transaction()
39 await transaction.get({})
41 ).get(date.toUTCString('yyyyMMdd'), {})
43 ).push(transaction.json_to_logjson(query))
46 // send email (asynchronously)
47 let emailjs_contact = await env.site.get_emailjs(
48 '/_config/email_contact.json'
52 from: globals.contact_from,
54 `${query.first_name} ${query.last_name} <${query.email}>`,
55 to: globals.contact_to,
57 Object.prototype.hasOwnProperty.call(query, 'company') ?
58 'Enquiry: ' + query.company :
64 console.error(err.stack || err.message)
66 console.log('sent contact email:', query.email)
68 ) // ignore returned promise
70 p {'Thanks! We\'ll be in touch as soon as we can.'}
73 p {'Do you require more information or consulting assistance with integrating the projects on this site? We\'d love to hear from you.'}
75 form#contact-form(method="post" action="index.html" role="form") {
79 label(for="contact_form_first_name") {'First name *'}
80 input.form-control#contact_form_first_name(type="text" name="first_name" placeholder="Please enter your first name" required="required" data-error="First name is required.") {}
81 div.help-block.with-errors {}
86 label(for="contact_form_last_name") {'Last name *'}
87 input.form-control#contact_form_last_name(type="text" name="last_name" placeholder="Please enter your last name" required="required" data-error="Last name is required.") {}
88 div.help-block.with-errors {}
95 label(for="contact_form_company") {'Company'}
96 input.form-control#contact_form_company(type="text" name="company" placeholder="Please enter your company") {}
97 div.help-block.with-errors {}
102 label(for="contact_form_email") {'Email *'}
103 input.form-control#contact_form_email(type="email" name="email" placeholder="Please enter your email" required="required" data-error="Valid email is required.") {}
104 div.help-block.with-errors {}
111 label(for="contact_form_message") {'Message *'}
112 textarea.form-control#contact_form_message(name="message" placeholder="Please explain your application" rows="4" required="required" data-error="Please, leave us a message.") {}
113 div.help-block.with-errors {}
117 p {} // fix this later
120 button.btn.btn-success.btn-send(type="submit") {'Send message'}
123 p {} // fix this later
128 'These fields are required.'
129 //'Contact form template by '
130 //a(href="https://bootstrapious.com/p/how-to-build-a-working-bootstrap-contact-form" target="_blank") {'Bootstrapious'}