PHP:Form Series, Part 2: Formtypes & Setting Default Values
(Page 2 out of 3)In the previous examples, I used inline form types. The form types were included in the form HTML. But you can also use external form types. This allows you to create a certain form style, and use this style in different forms.
An external form type must follow a certain format, which looks like this:
(View live external form type)
This is very simple XML, and shouldn't be hard to understand.
You must also link the external form type in your form, using the src attribute on a formtype tag, like so:
"submit" value="Go!" />
The src must be a path to your external form type file, e.g. /home/you/public_html/external.xml or simply external.xml if the form type file is in the same directory as your form.
External form types give you tremendous power, and can be used to give all your forms a slick look, without having to write much HTML at all. Just write it once, and be done with it!
Two special form types
There are two special form types called 'begin' and 'end' (e.g.
[CDATA[
"text" name="{var:name}" />
]]>
[CDATA[
[CDATA[
]]>
"submit" value="Go!" />
When using a custom form begin or end, you mustn't forget to include
. If you forget this, your form will most likely not work, and could cause errors.I hope you now understand what form types are, and how powerful they are. They can really make your life easier, especially when using external form types. Just link 'em, and use 'em! Let's now have a look at my favorite feature: setting default values.