Textpattern : Forms
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 single 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:
This is how to turn that footer into a Textpattern form:
- Cut the footer code out of the Textpattern page.
- Go to Presentation, then Forms.
- Click the New form link:
- Paste the footer code into the Form code box:
- In the Form name box, give the footer a name, such as … well, ‘footer’.
- From the drop-down Form type list, select Miscellaneous. 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.
- Click Save. Textpattern will not remind you to save your work.
- Now we need to tell Textpattern to insert the footer into 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" />
This is how the Textpattern page looks now: - Click Save. Textpattern won’t remind … oh, you already know that.
The Textpattern Form Tag
The Textpattern tag you have just used comes in two parts:
<txp:output_form />
This means: insert the contents of 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 in self-closing tags 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.
Incidentally, 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, one-line piece of code into each Textpattern page.
You can use this technique anywhere in your website, wherever you have self-contained blocks of code or text 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 intended to introduce the Textpattern content management system to web designers who have no knowledge of PHP or databases.]