Skip to main content

Bootstrap 3

The following example assumes you're including necessary Bootstrap 3 JS and CSS. You can place the additional CSS and JS inside the formatting template or add to your site's CSS / JS files.

Bootstrap 3 has reached end of life and no longer receives critical security updates. You should consider updating to Bootstrap 5.

Formatting

{# Opening <form> tag #}
{{ form.renderTag }}

{# Display page tabs if Multi-page form #}
{% if form.pages|length > 1 %}
<ul class="nav nav-tabs">
{% for page in form.pages %}
<li class="nav-item">
<span class="nav-link{{ form.currentPage.index == page.index ? ' font-weight-bold active' : ' disabled' }}">{{ page.label }}</span>
</li>
{% endfor %}
</ul>
{% endif %}

{# Display Error banner and general errors if applicable #}
{% if form.hasErrors %}
<div class="alert alert-danger">
{{ "Error! Please review the form and try submitting again."|t('freeform') }}

{% if form.errors|length %}
<ul>
{% for error in form.errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</div>
{% endif %}

{# Render form fields #}
{% for row in form %}
<div class="row {{ form.customAttributes.rowClass }}">
{% for field in row %}
{% set width = (12 / (row|length)) %}

{% set isCheckbox = field.type in ["checkbox","mailing_list"] %}

{% set columnClass = isCheckbox ? "checkbox" : "form-group" %}
{% set columnClass = columnClass ~ (field.errors|length ? " has-error" : "") %}
{% set columnClass = columnClass ~ form.customAttributes.columnClass %}
{% set columnClass = columnClass ~ " col-sm-" ~ width ~ " col-xs-12" %}

{% if field.type == "submit" %}
{% set columnClass = columnClass ~ " submit-align-" ~ field.position %}
{% endif %}

<div class="{{ columnClass }}"{{ field.rulesHtmlData }}>

{% if field.type == "checkbox_group" %}

{{ field.renderLabel({
labelClass: (field.required ? " required" : ""),
instructionsClass: "help-block",
errorClass: "help-block",
}) }}

{% if field.oneLine %}
<div>
{% for option in field.options %}
<label class="checkbox-inline">
<input type="checkbox"
name="{{ field.handle }}[]"
value="{{ option.value }}"
{{ option.checked ? "checked" : "" }}
/>
{{ option.label|t('freeform')|raw }}
</label>
{% endfor %}
</div>
{% else %}
{% for option in field.options %}
<div class="checkbox">
<label>
<input type="checkbox"
name="{{ field.handle }}[]"
value="{{ option.value }}"
{{ option.checked ? "checked" : "" }}
/>
{{ option.label|t('freeform')|raw }}
</label>
</div>
{% endfor %}
{% endif %}

{{ field.renderInstructions() }}
{{ field.renderErrors() }}

{% elseif field.type == "radio_group" %}

{{ field.renderLabel({
labelClass: (field.required ? " required" : ""),
instructionsClass: "help-block",
errorClass: "help-block",
}) }}

{% if field.oneLine %}
<div>
{% for option in field.options %}
<label class="radio-inline">
<input type="radio"
name="{{ field.handle }}"
value="{{ option.value }}"
{{ option.checked ? "checked" : "" }}
/>
{{ option.label|t|raw }}
</label>
{% endfor %}
</div>
{% else %}
{% for option in field.options %}
<div class="radio">
<label>
<input type="radio"
name="{{ field.handle }}"
value="{{ option.value }}"
{{ option.checked ? "checked" : "" }}
/>
{{ option.label|t('freeform')|raw }}
</label>
</div>
{% endfor %}
{% endif %}

{{ field.renderInstructions() }}
{{ field.renderErrors() }}

{% elseif field.type == "dynamic_recipients" and (field.showAsRadio or field.showAsCheckboxes) %}

{{ field.renderLabel({
labelClass: (field.required ? " required" : ""),
instructionsClass: "help-block",
errorClass: "help-block",
}) }}

{% if field.oneLine %}
<div>
{% for option in field.options %}
<label class="{{ field.showAsRadio ? "radio" : "checkbox" }}-inline">
<input type="{{ field.showAsRadio ? "radio" : "checkbox" }}"
name="{{ field.handle }}[]"
value="{{ loop.index0 }}"
{{ option.checked ? "checked" : "" }}
/>
{{ option.label|t|raw }}
</label>
{% endfor %}
</div>
{% else %}
{% for option in field.options %}
<div class="{{ field.showAsRadio ? "radio" : "checkbox" }}">
<label>
<input type="{{ field.showAsRadio ? "radio" : "checkbox" }}"
name="{{ field.handle }}[]"
value="{{ loop.index0 }}"
{{ option.checked ? "checked" : "" }}
/>
{{ option.label|t('freeform')|raw }}
</label>
</div>
{% endfor %}
{% endif %}

{{ field.renderInstructions() }}
{{ field.renderErrors() }}

{% elseif field.type == "signature" %}

{{ field.render({ class: "btn btn-light" }) }}

{% elseif field.type == "submit" %}

{{ field.render({ class: "btn btn-primary" }) }}

{% elseif field.type == "cc_details" %}

{# FOR FREEFORM PAYMENTS #}

{{ field.renderLabel({
labelClass: (field.required ? " required" : ""),
instructionsClass: "help-block",
errorClass: "help-block",
}) }}

{% for layoutRow in field.layoutRows %}
<div class="row {{ form.customAttributes.rowClass }}">
{% for layoutField in layoutRow %}
{% set layoutWidth = (12 / (layoutRow|length)) %}
{% set columnClass = columnClass|replace(' col-sm-' ~ width) %}
{% set columnClass = columnClass ~ " col-sm-" ~ layoutWidth %}
<div class="{{ columnClass }}">
{{ layoutField.render({
class: isCheckbox ? "checkbox" : "form-control",
instructionsClass: "help-block",
instructionsBelowField: true,
labelClass: (layoutField.required ? " required" : ""),
errorClass: "help-block",
}) }}
</div>
{% endfor %}
</div>
{% endfor %}

{{ field.renderInput({
instructionsClass: "help-block",
instructionsBelowField: true,
labelClass: (field.required ? " required" : ""),
errorClass: "help-block",
}) }}

{{ field.renderInstructions }}
{{ field.renderErrors }}

{% else %}

{{ field.render({
class: isCheckbox ? "checkbox" : "form-control",
instructionsClass: "help-block",
instructionsBelowField: true,
labelClass: (field.required ? " required" : ""),
errorClass: "help-block",
}) }}

{% endif %}
</div>
{% endfor %}
</div>
{% endfor %}

{# Closing </form> tag #}
{{ form.renderClosingTag }}

CSS

The following CSS is a supplemental starting point to get forms appearing robustly.

button[type='submit'].ff-loading {
display: inline-flex;
flex-wrap: nowrap;
align-items: center;
}
button[type='submit'].ff-loading:before {
content: '';
display: block;
flex: 1 0 11px;
width: 11px;
height: 11px;
margin-right: 10px;
border-style: solid;
border-width: 2px;
border-color: transparent transparent #fff #fff;
border-radius: 50%;
animation: ff-loading 0.5s linear infinite;
}
@keyframes ff-loading {
0% {
transform: rotate(0);
}
100% {
transform: rotate(1turn);
}
}
label.required:after {
content: '*';
color: #d00;
margin-left: 5px;
}
.submit-align-left {
text-align: left;
}
.submit-align-right {
text-align: right;
}
.submit-align-center {
text-align: center;
}
.submit-align-center button:not(:first-of-type),
.submit-align-left button:not(:first-of-type),
.submit-align-right button:not(:first-of-type) {
margin-left: 5px;
}
.submit-align-spread button:first-child {
float: left;
}
.submit-align-spread button:last-child {
float: right;
}

JS

The following JS is a supplemental starting point to handle additional elements in the form.

// Styling for AJAX responses
document.addEventListener('freeform-ready', function (event) {
var freeform = event.target.freeform;
freeform.setOption('errorClassBanner', ['alert', 'alert-danger', 'errors']);
freeform.setOption('errorClassList', ['help-block', 'errors', 'has-error']);
freeform.setOption('errorClassField', 'has-error');
freeform.setOption('successClassBanner', [
'alert',
'alert-success',
'form-success',
]);
});
// Styling for Stripe Payments field
document.addEventListener('freeform-stripe-styling', function (event) {
event.detail.base = {
fontSize: '16px',
fontFamily:
'-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"',
};
});

The following CDN links for Bootstrap 3 are for v3.4.1. Please see official Bootstrap 3 documentation for latest versions and CDN links.

<!-- Latest compiled and minified CSS -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap.min.css"
integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu"
crossorigin="anonymous"
/>

<!-- Optional theme -->
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/css/bootstrap-theme.min.css"
integrity="sha384-6pzBo3FDv/PJ8r2KRkGHifhEocL+1X2rVCTTkUfGk7/0pbek5mMa1upzvWbrUbOZ"
crossorigin="anonymous"
/>

<!-- Latest compiled and minified JavaScript -->
<script
src="https://cdn.jsdelivr.net/npm/bootstrap@3.4.1/dist/js/bootstrap.min.js"
integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
crossorigin="anonymous"
></script>