Forms

Creating Forms

Create forms as reusable partials when they are meant to be placed in templates, pages, or layouts.

Form Partials#

TemplateX creates starter forms in:

          • contact.php

You can also create these files by hand.

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

Use the partial anywhere:

phpresources/views/contact.php
<Forms.Contact />

Form Names#

The name after form: becomes the form key:

php
{{ form:newsletter }}  ...{{ /form:newsletter }}

Names are normalized to safe keys. first-name and first_name are treated as first_name internally.

Form Attributes#

Attributes on the TemplateX form tag are passed to the generated <form> element:

php
{{ form:contact class="contact-form" redirect="/thank-you/" }}  ...{{ /form:contact }}

redirect sends successful non-AJAX submissions to another URL.

If you write your own literal <form> element inside the TemplateX form, TemplateX keeps its useful attributes and replaces it with the generated form element.