Forms

Forms

Forms let you write normal HTML form markup while TemplateX adds submission handling, validation, errors, success states, storage, and email settings in the generated theme.

The Form Shape#

A TemplateX form starts with a paired form tag:

phpresources/views/partials/forms/contact.php
{{ form:contact }}  <form>    <label>Name</label>    <input name="name" required>    {{ form:error:name }}    <label>Email</label>    <input name="email" type="email" required>    {{ form:error:email }}    {{ form:success }}      <p>Thanks, {{ name }}.</p>    {{ /form:success }}    <button type="submit">Send</button>  </form>{{ /form:contact }}

TemplateX discovers the fields from the inputs and compiles the form to native PHP.