A newer version of

Freeform

is available.

Try Freeform 5 now →

Freeform Freeform for Craft

Formatting Templates

Materialize

The following example assumes you're including necessary Materialize JS and CSS.

WARNING

Materialize has been abandoned, but the community has forked it and regularly maintains it.

Preview

N/A

Formatting

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

{# Display page tabs if Multi-page form #}
{% if form.pages|length > 1 %}
  <ul class="pagination">
    {% for page in form.pages %}
      <li class="{{ form.currentPage.index == loop.index0 ? "active" : "disabled" }}">
        <a href="javascript:;">{{ page.label }}</a>
      </li>
    {% endfor %}
  </ul>
{% endif %}

{# Display Error banner and general errors if applicable #}
{% if form.hasErrors %}
  <div class="alert alert-danger errors">
    {{ "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 = field.type in ["radio_group", "checkbox_group"] ? "" : "input-field" %}
      {% set columnClass = columnClass ~ (field.errors|length ? " has-error" : "") %}
      {% set columnClass = columnClass ~ form.customAttributes.columnClass %}
      {% set columnClass = columnClass ~ " col m" ~ width ~ " s12" %}

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

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

        <div class="{{ columnClass }}" style="margin-bottom: 20px;"{{ field.rulesHtmlData }}>

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

          {% for option in field.options %}
            <p>
              <input type="checkbox"
                   id="{{ form.hash ~ field.handle ~ option.value }}"
                   name="{{ field.handle }}"
                   value="{{ option.value }}"
                  {{ option.value in field.value ? "checked" : "" }}
              />
              <label for="{{ form.hash ~ field.handle ~ option.value }}">{{ option.label|t('freeform')|raw }}</label>
            </p>
          {% endfor %}

          {{ field.renderInstructions }}
          {{ field.renderErrors }}
        </div>

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

        <div class="{{ columnClass }}" style="margin-bottom: 20px;"{{ field.rulesHtmlData }}>

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

          {% for option in field.options %}
            <p>
              <input type="radio"
                   id="{{ form.hash ~ field.handle ~ option.value }}"
                   name="{{ field.handle }}"
                   value="{{ option.value }}"
                  {{ option.value in field.value ? "checked" : "" }}
              />
              <label for="{{ form.hash ~ field.handle ~ option.value }}">{{ option.label|t('freeform')|raw }}</label>
            </p>
          {% endfor %}

          {{ field.renderInstructions }}
          {{ field.renderErrors }}
        </div>

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

        <div class="{{ columnClass }}" style="margin-bottom: 20px;"{{ field.rulesHtmlData }}>

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

          {% for option in field.options %}
            <p>
              <input type="{{ field.showAsRadio ? "radio" : "checkbox" }}"
                   id="{{ form.hash ~ field.handle ~ option.value }}"
                   name="{{ field.handle }}[]"
                   value="{{ loop.index0 }}"
                  {{ option.value in field.value ? "checked" : "" }}
              />
              <label for="{{ form.hash ~ field.handle ~ option.value }}">{{ option.label|t('freeform')|raw }}</label>
            </p>
          {% endfor %}

          {{ field.renderInstructions }}
          {{ field.renderErrors }}
        </div>

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

        <div class="{{ columnClass }}"{{ field.rulesHtmlData }}>
          {{ field.renderInput({
            class: 'materialize-textarea'
          }) }}
          {{ field.renderLabel }}

          {{ field.renderInstructions }}
          {{ field.renderErrors }}
        </div>

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

        <div class="{{ columnClass|replace('input-field', '') }}"{{ field.rulesHtmlData }}>

          {{ field.renderInput }}
          {{ field.renderLabel({
            instructionsClass: "help-block",
            errorClass: "help-block",
          }) }}

          {{ field.renderInstructions() }}
          {{ field.renderErrors() }}
        </div>

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

        <div class="{{ columnClass|replace('input-field', '') }}"{{ field.rulesHtmlData }}>

          {{ field.renderInput|replace('<label>', '')|replace('</label>', '')|replace(field.label, '')|raw }}
          {{ field.renderLabel({
            instructionsClass: "help-block",
            errorClass: "help-block",
          }) }}

          {{ field.renderInstructions() }}
          {{ field.renderErrors() }}
        </div>

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

        <div class="{{ columnClass }}"{{ field.rulesHtmlData }}>
          {{ field.render({
            class: "btn btn-large waves-effect waves-light"
          }) }}
        </div>

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

        <div class="{{ columnClass }}">
          {{ field.renderInput }}
        </div>

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

        <div class="{{ columnClass|replace('input-field', '') }} file-field input-field"{{ field.rulesHtmlData }}>
          <div class="btn">
            <span>File</span>
            {{ field.renderInput }}
          </div>
          <div class="file-path-wrapper">
            <input class="file-path validate"
                 type="text"
                 placeholder="{{ field.label }}"
            />
          </div>

          {{ field.renderInstructions }}
          {{ field.renderErrors }}
        </div>

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

        {# FOR FREEFORM PAYMENTS #}

        <div class="{{ columnClass|replace('input-field', '') }}"{{ field.rulesHtmlData }}>
          {{ field.renderLabel }}

          {% for layoutRow in field.layoutRows %}
            <div class="row {{ form.customAttributes.rowClass }}">
              {% set layoutWidth = (12 / (layoutRow|length)) %}
              {% set columnClass = columnClass|replace(' m' ~ width) %}
              {% set columnClass = columnClass ~ " m" ~ layoutWidth %}
              {% for layoutField in layoutRow %}
                <div class="{{ columnClass }}">
                  {{ layoutField.renderInput({
                    class: " select-wrapper chips",
                    instructionsClass: "help-block",
                    instructionsBelowField: true,
                    errorClass: "help-block",
                    inputAttributes: { style: "padding-top: 1rem" },
                  }) }}
                  {{ layoutField.renderLabel({labelClass: " select-label" ~ (layoutField.required ? " required" : "")}) }}

                  {{ layoutField.renderInstructions }}
                  {{ layoutField.renderErrors }}
                </div>
              {% endfor %}
            </div>
          {% endfor %}

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

          {{ field.renderInstructions }}
          {{ field.renderErrors }}
        </div>

      {% else %}

        <div class="{{ columnClass }}"{{ field.rulesHtmlData }}>
          {{ field.renderInput({
            instructionsClass: "help-block",
            instructionsBelowField: true,
            labelClass: (field.required ? " required" : ""),
            errorClass: "help-block",
          }) }}
          {{ field.renderLabel }}

          {{ field.renderInstructions }}
          {{ field.renderErrors }}
        </div>

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

{# Closing </form> tag #}
{{ form.renderClosingTag }}
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259

The following CDN links for Foundation are for v1.0.0, which may no longer be the latest version. Please see official Materialize documentation for latest versions and CDN links.

<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">

<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
1
2
3
4
5