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 3 out of 3)

This is one the coolest features of PHP:Form, and I really love it. I'm sure you, at some time point, had to set the default values of a form, most likely when presenting the editing form of a database item. The text fields are easy; just add a value="" to the input field. But selects, radio buttons and checkboxes are the real tricky parts. You must set the appropriate option to selected, and check the right boxes. A real pain and a hassle. You usually wind up with some HTML/PHP mess, and loads of if-statements.

But with PHP:Form that's no longer a problem. All you need to do is set the value of a field using the $_FORMS->set_value ('form', 'field', 'value') command. It even accepts arrays as a value for checkboxes. To see what I'm talking about, check out the demo below:

        Text field: "text" name="textfld" />


        Radio: "radio" name="radiofld" value="yes" />Yes
        "radio" name="radiofld" value="no" />No

        "checkbox" name="checkfld" value="one" />One
        "checkbox" name="checkfld" value="two" />Two
        "checkbox" name="checkfld" value="three" />Three
        "checkbox" name="checkfld" value="four" />Four
        "checkbox" name="checkfld" value="five" />Five
        "checkbox" name="checkfld" value="six" />Six

        "submit" value="Go!" />

// Set default values
$_FORMS->set_value ('example', 'textfld', 'Some example value');
$_FORMS->set_value ('example', 'selectfld', 'green');
$_FORMS->set_value ('example', 'radiofld', 'no');
$_FORMS->set_value ('example', 'checkfld', array('two', 'four', 'six'));

(View Live Demo)

See how neat it is? It really makes it easier to set default values, and no more messing around with if-statements and mixed HTML and PHP!


This is the final part of our PHP:Form series, and I hope I've been able to show you what PHP:Form is, and what it can do. If you have any more questions, comments or anything else, you can always contact me directly (use the contact form at or contact TPG PHP Scripts ([email protected]) or use their Community Support Forums.

I've been using PHP:Form myself now for the last few months, and it has definitely made my life easier when it comes to creating PHP scripts. Creating admin control panels and such is especially easier now, and it literally takes me 5 minutes to create a complete, good-looking, form with validators and everything. Now that's rapid development, I tell ya!

If you're interested in purchasing PHP:Form, don't forget the to use the special phpit coupon. To use this coupon, use the coupon code phpit. It gives you a 10% discount!

Visit the PHP:Form Product Page

« Previous: 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