Embeddable Forms
Embed beautiful, customizable forms on any website. Use our hosted form builder or customize with your own CSS.
Quick Start
Add a form to your website with a single script tag:
<script
src="https://townhall.gg/embed.js"
data-form-id="YOUR_FORM_ID"
></script>Go to your dashboard, click on any form, and copy the Form ID from the Setup tab.
Embed Types
Choose from four different embed styles:
Inline (Default)
Embeds the form directly in your page content.
<script
src="https://townhall.gg/embed.js"
data-form-id="YOUR_FORM_ID"
data-type="inline"
></script>Popup Modal
Shows a button that opens the form in a centered modal.
<script
src="https://townhall.gg/embed.js"
data-form-id="YOUR_FORM_ID"
data-type="popup"
data-button-text="Contact Us"
></script>Slide-in Panel
Shows a button that slides in a panel from the right side.
<script
src="https://townhall.gg/embed.js"
data-form-id="YOUR_FORM_ID"
data-type="slide"
data-button-text="Get in Touch"
></script>Floating Button
Adds a floating button in the corner that opens a popup form.
<script
src="https://townhall.gg/embed.js"
data-form-id="YOUR_FORM_ID"
data-type="floating"
data-position="bottom-right"
data-button-text="💬 Contact"
></script>Customization Options
Customize the appearance with data attributes:
<script
src="https://townhall.gg/embed.js"
data-form-id="YOUR_FORM_ID"
data-type="popup"
data-theme="dark"
data-accent="6366f1"
data-radius="12"
data-button-text="Contact Sales"
data-button-color="6366f1"
data-hide-title="true"
data-hide-branding="true"
data-width="500px"
data-css="https://example.com/custom-form.css"
></script>All Options
| Attribute | Description | Default |
|---|---|---|
data-form-id | Your form ID (required) | - |
data-type | inline, popup, slide, floating | inline |
data-theme | light, dark, auto | auto |
data-accent | Accent color (hex without #) | 3b82f6 |
data-radius | Border radius in pixels | 8 |
data-button-text | Text for trigger button | Contact Us |
data-button-color | Button background color (hex) | Same as accent |
data-position | bottom-right, bottom-left (floating only) | bottom-right |
data-width | Popup/slide width | 440px |
data-hide-title | Hide form title | false |
data-hide-branding | Hide "Powered by TownHall" | false |
data-css | URL to custom CSS file | - |
Iframe Embed
For more control, embed the form using an iframe:
<iframe
src="https://townhall.gg/embed/YOUR_FORM_ID?theme=light&accent=6366f1"
width="100%"
height="500"
style="border: none;"
></iframe>URL Parameters
Customize via query parameters:
https://townhall.gg/embed/YOUR_FORM_ID
?theme=dark
&accent=6366f1
&radius=12
&hideTitle=true
&hideBranding=true
&css=https://example.com/custom.cssForm Builder
Create custom forms with our visual form builder. Access it from the "Builder" tab in your form details.
Supported Field Types
- Text - Single line text input
- Email - Email address with validation
- Phone - Phone number input
- URL - Website URL input
- Number - Numeric input with min/max
- Textarea - Multi-line text
- Dropdown - Select from options
- Radio - Single choice from options
- Checkbox - Multiple selections or single toggle
- Date - Date picker
- Time - Time picker
- File - File upload
- Hidden - Hidden field with preset value
Field Options
Each field supports:
- Label - Display text shown above the field
- Field Name - Key used in submission data
- Placeholder - Hint text inside the field
- Help Text - Description shown below the field
- Required - Make the field mandatory
- Width - Full or half width for layout
Custom CSS
Override default styles by providing a URL to your own CSS file. The form uses CSS variables that you can customize:
/* Custom form styles */
:root {
--embed-bg: #ffffff;
--embed-bg-secondary: #f9fafb;
--embed-text: #111827;
--embed-text-secondary: #6b7280;
--embed-text-muted: #9ca3af;
--embed-border: #e5e7eb;
--embed-input-bg: #ffffff;
--embed-accent: #3b82f6;
--embed-radius: 8px;
}
/* Example: Custom submit button */
.submitButton {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
font-weight: 700;
text-transform: uppercase;
letter-spacing: 1px;
}
/* Example: Custom field styling */
.field input,
.field textarea {
border-width: 2px;
font-size: 16px;
}Your CSS file must be served with CORS headers allowing cross-origin requests, or hosted on the same domain as your website.
JavaScript Events
Listen for form events using postMessage:
window.addEventListener('message', (event) => {
// Form submitted successfully
if (event.data.type === 'townhall:submit') {
console.log('Form submitted!', {
formId: event.data.formId,
submissionId: event.data.submissionId,
data: event.data.data
});
// Track conversion
gtag('event', 'form_submission', {
form_id: event.data.formId
});
}
// Form requested a redirect
if (event.data.type === 'townhall:redirect') {
window.location.href = event.data.url;
}
// Form height changed (for iframe resizing)
if (event.data.type === 'townhall:resize') {
const iframe = document.querySelector('iframe');
if (iframe) {
iframe.style.height = event.data.height + 'px';
}
}
});Examples
Contact Form with Dark Theme
<script
src="https://townhall.gg/embed.js"
data-form-id="YOUR_FORM_ID"
data-type="inline"
data-theme="dark"
data-accent="22c55e"
></script>Floating Support Widget
<script
src="https://townhall.gg/embed.js"
data-form-id="YOUR_FORM_ID"
data-type="floating"
data-position="bottom-right"
data-button-text="💬 Need Help?"
data-theme="auto"
></script>Newsletter Signup Popup
<!-- Trigger button -->
<button onclick="openNewsletterForm()">Subscribe to Newsletter</button>
<script src="https://townhall.gg/embed.js"
id="newsletter-form"
data-form-id="YOUR_FORM_ID"
data-type="popup"
data-theme="light"
data-hide-branding="true"
></script>