Textpattern : Forms

Textpattern logo

Once you are able to create a static website with Textpattern’s pages and sections, you can move on to the feature of Textpattern that begins to exploit the power of databases: Textpattern forms.

What is a Textpattern Form?

Forget all about HTML forms such as contact forms. Textpattern forms are completely different.

Perhaps forms isn’t the best name for them. Other content management systems have similar features, and call them something like snippets or chunks.

Think of a Textpattern form as a versatile, self–contained unit of code or text.

Blocks of Code or Text

Most websites contain blocks of code or text, such as the navigation menu and the footer, that are identical on more than one page. Textpattern allows you to manage these self–contained blocks efficiently by placing each of them in a separate document, and automatically copying that document into each HTML page. This offers two benefits:

  • Changing just one document is quicker and less prone to error than changing many identical copies.
  • The total amount of code is usually reduced.

How to Use a Textpattern Form

To see how it works, go back to a Textpattern page that contains your complete HTML page. Let’s assume that the footer is the same on every HTML page of the website:

Textpattern page screen

This is how to turn that footer into a Textpattern form:

  1. Cut the footer out of the Textpattern page.
  2. Go to Presentation, then Forms.
  3. Click Create new form.Textpattern form screen
  4. Paste the footer into the box.
  5. Below the box, give the footer a name, such as … well, ‘footer’.
  6. From the drop–down Type list, select misc. There are various types of Textpattern form, each of which is for use in certain situations. A standard chunk of code or text, such as a footer or a navigation menu, qualifies as a miscellaneous form.Textpattern form save screen
  7. Click Save New. Textpattern will not remind you to save your work.
  8. Now we need to tell Textpattern to insert the footer in each page. Go to the area of the Textpattern page that was previously occupied by the footer, and add this piece of code:
    <txp:output_form form="footer" />
  9. Click Save. Textpattern won’t remind … oh, you already know that.

This is how the Textpattern page looks now:

Textpattern page screen

The Textpattern Form Tag

The Textpattern tag you have just used comes in two parts:

  • <txp:output_form />
    This means: insert a Textpattern miscellaneous form here.
  • form="footer"
    This tells the software which form to use. If you don’t tell Textpattern which form to use, it will normally use the default form, which may or may not be what you want. It’s a good idea always to specify the name of the form.

Formatting

All Textpattern tags use XHTML formatting: everything is in lower–case, and there is a space before the closing slash. Feel free to use HTML 4 or HTML 5 in your website, but your Textpattern tags must follow the XHTML pattern.

Several Textpattern tags, both built–in and generated through plug–ins, function as a shorthand way of placing code on a web page, and may produce XHTML code by default, although some will give you the option of specifying HTML formatting.

Textpattern Forms are Versatile

No matter how much material you have in your website’s footer, or how many HTML pages your website contains, all you need to do is place the same simple piece of code into each Textpattern page.

You can use this technique anywhere in your website, wherever you have self–contained blocks of code that appear more than once. You can even place Textpattern forms inside other Textpattern forms.

As well as inserting self–contained units such as footers or navigation menus or doctypes into a website, Textpattern forms can be used to insert Textpattern articles into a website. And what’s an article? Read on …

Next …

Continue with the next article: Textpattern Articles.

[This tutorial is part 3 of a series by Jeremy Bojczuk intended to introduce the Textpattern content management system to web designers who have no knowledge of PHP or databases.]

Textpattern Links

Top

Valid XHTML1.0 Strict