ASPit - Totally ASP JSit - Totally JavaScript
Search PHPit

Use this textbox to search for articles on PHPit. Seperate keywords with a space.


PHP:Form Series, Part 2: Formtypes & Setting Default Values

(Page 1 out of 3)

Welcome to the second part of the PHP:Form Series. In the previous part I explained exactly what PHP:Form is, and one of its core features; inbuilt validators. In case you have forgotten, or haven't read that part yet, it might be wise to read it before reading this part. I'm assuming you have a reasonable understanding of how PHP:Form works.

In this part we're going to have a look at "form types" and the ability to set the default values using PHP. I've also included several code examples and live demos.

Form Types

What are they?
Form types can be used to "re-define" new types of fields. Basically, they are templates that can be used in your PHP:Form. They can save you a lot of time when creating forms, and especially when you need to re-use a certain HTML part often, form types are a real time saver. The below example demonstrates a simple form type:

                "text" name="{var:name}" />

        "mytype" label="Name:" name="name" />
        "mytype" label="Email:" name="email" />

        "submit" value="Go!" />

(View Live Demo)

As you can see two text fields will be shown, but we've only had to write the HTML for it once. You can create an unlimited amount of form types, and you can even create form types that don't even contain a field, e.g.

                This isn't even a {var:bla}



(View Live Demo)

As you might have noticed, you can also use variables. These variables are in the format of {var:attribute_name}. You can use any variable name you like, and simply pass the value of that variable as an attribute on the formfield tag (like I did in the examples).

Next: Different kinds of form types »

Leave a Reply

About the author
Dennis Pallett is the main contributor to PHPit. He owns several websites, including ASPit and Chill2Music. He is currently still studying.
Article Index
  1. Introduction
  2. Different kinds of form types
  3. Setting Default Values
Bookmark Article
Download Article
Download this article as a PDF file