Forms — Balancee HTML
The Balancee HTML template has two forms: the contact form (“Tell us about your project.”) on the Contact page and the Services page, and the newsletter box in the footer of every page. Both send to the form service or webhook of your choice.
The contact form checks the required fields and the e-mail address before sending (and shows “Please fill out this field.” or “Please enter a valid email address.” under the field), shows a turning ring while sending, says “Thank you” and clears the fields, keeps what the visitor typed when something fails (“Something went wrong”), and drops spam with a hidden honeypot field.
Out of the box both run in demo mode: nothing is sent, and the fields are logged in the browser console. Pick a destination before you publish.
Connect a form service
Section titled “Connect a form service”A static site has no server of its own, so submissions go to a form service or a webhook. All of these have a free tier:
| Service | What it does | formEndpoint |
|---|---|---|
| Formspree | Emails you each submission | https://formspree.io/f/<form id> |
| Web3Forms | Emails you each submission, no account needed | https://api.web3forms.com/submit, and your key in formAccessKey |
| Getform, Basin | Inbox, email, integrations | The form’s endpoint URL |
| Zapier, Make, n8n, Pipedream | Send submissions anywhere: Google Sheets, Slack, a CRM, your calendar or booking tool | The webhook (“catch hook”) URL |
-
Create a form at the service and copy its endpoint.
-
Open
assets/js/config.jsand paste it:window.siteConfig = {formEndpoint: "https://formspree.io/f/abcdwxyz",formAccessKey: "", // Web3Forms only}; -
Serve the folder (
npx serve .), send a request from the Contact page and check that it arrived. -
Upload
config.jswith the site.
Every page loads the same config.js, so the two copies of the contact form (Contact and Services) send to the same
place. The sample forms in style-guide.html stay in demo mode whatever you set there (they carry data-form-demo),
so they never send anything.
What the service receives
Section titled “What the service receives”Each field by its name, as multipart/form-data:
| Field | Name | Required |
|---|---|---|
| Name | Name |
yes |
| Company | Company |
yes |
Email |
yes | |
| Phone | Phone |
|
| I’m interested in … (radio buttons, one choice) | Service (the service’s name: Business strategy, Innovation & growth …) |
|
| Tell us about your project. | Message |
The form also sends form (contact) and subject (“New message from the Balancee contact form”), so you can tell its
messages apart in your inbox or tool. With formAccessKey set, it also sends it as access_key. The honeypot field
(fax) is left out. The request asks for a JSON answer (Accept: application/json), so the service answers the page
instead of showing its own thank-you page.
The newsletter box
Section titled “The newsletter box”The footer’s box (“Never Miss an Update — Subscribe!”) is a second form: one field (Email, required) and a “Join Now”
button. config.js does not set its endpoint: the script reads the form’s own action attribute, so until you add
one the box stays in demo mode (it logs the e-mail in the console and answers “Thank you”). In every page’s footer, add
the address to the <form data-newsletter …> tag:
<form data-newsletter action="https://formspree.io/f/abcdwxyz" data-submit-label="Join Now" data-success="Thank you" data-error="Try again" method="post" …>The footer is the same in all 35 files, so use find and replace in files: search for data-submit-label="Join Now" and
replace it with action="…" data-submit-label="Join Now". For Web3Forms add a hidden field next to the others in the
form: <input type="hidden" name="access_key" value="your-key" />. The box sends Email, form (newsletter) and
subject (“New newsletter subscriber”), in the same way as the contact form. What the visitor sees: the button shows
“…” while sending, then “Thank you” (the e-mail is sent) or “Try again” (the address isn’t valid, or the service
failed), and the field is cleared. The texts are the form’s data-success, data-error and data-submit-label; change
them there. The newsletter box has no redirect.
The service you choose decides what happens next (a list of subscribers, an e-mail to you, your mailing tool through a webhook).
Changing the fields
Section titled “Changing the fields”The fields are ordinary <input> and <textarea> elements inside the <form data-form> of contact.html and
service.html: change both. Each field is a <label data-field="…"> with its label text in a <span> above the
control, so the visible label is also the field’s name for screen readers:
<label data-field="Phone" class="flex flex-col gap-2.5" ><span class="text-sm … text-grey">Phone</span ><input name="Phone" placeholder="Phone Number" type="tel" autocomplete="tel" class="…"/></label>The fields sit two per row from tablets up (one column on phones); the services and the message take the whole width
(md:col-span-2).
- To make a field required, add
requiredto it. The form checks it before sending and focuses the first field that fails. To show a message under it, copy the name’s<span id="Name-error" data-field-error hidden …>into its<label>with a newid(Phone-error) and your text. - To add a field, copy a
<label data-field …>…</label>, give the control a newnameand the label a new text. The service receives whatever the form contains, so there are no settings to update. Don’t name a fieldfax: it is the honeypot’s. - To change the services, edit the radio buttons in the
<fieldset>(“I’m interested in …”): each one’svalue(what you receive) and the<span>after it (what the visitor reads). Copy a<label>for one more. The choices are the eight services; keep them in step with the services you offer. - To remove a field, delete its
<label>.
A field arrives under its name, so keep the names you already map somewhere. The button’s texts are written in the
button: “Submit” twice (the second copy is read while the form is sending), “Thank you” and “Something went wrong”.
“Thank you” and “Something went wrong” are also in the form’s data-success and data-error, which screen readers
announce: change both. The title of each submission is the value of the hidden subject field: put your own wording
in it.
To send visitors to a page of your own after a successful send, add data-redirect="thank-you.html" to the <form>.
Testing before launch
Section titled “Testing before launch”- Send a request from the live site with a real address, and reply to the test; do the same with the newsletter box.
- The service must answer with a success status (2xx). If it doesn’t, the visitor sees “Something went wrong” (the
newsletter box: “Try again”) and keeps what they typed in the contact form. Try it once by pasting a wrong endpoint
into
config.json your local copy. - The browser console tells you what happened: in demo mode it logs
[forms] demo mode — set formEndpoint in assets/js/config.js to send submissionswith the fields; after a failure,[forms] could not send the formwith the reason.
Spam and privacy
Section titled “Spam and privacy”The honeypot stops the usual bots: both forms carry a hidden field named fax that a person never sees; a bot that
fills it is shown “Thank you” and nothing is sent. The services above filter spam on their side as well. The endpoint
is visible in the page source, which is how these services are designed to work.
Submissions go only where you point them. Most countries expect you to say what happens to the data people send you
(here a name, a company, contact details and a message): choose a form service whose terms fit your obligations, and
describe it in your privacy policy (legal/privacy-policy.html, a sample to rewrite). The forms have no consent
checkbox; the contact form says “By submitting, you agree to our Terms of Service and Privacy Policy” under the button.
Add a required checkbox if your visitors need one.