Apostolos Dountsis

Web Development & Desktop Application Solutions
  • rss
  • Home
  • Projects
    • Easy Peasy Image Gallery
    • Social Bookmarks
      • Social Bookmarks Release Notes
      • Social Bookmarks Supported Sites
    • Move Comments
  • Downloads
  • Freelance Services
  • Photo Gallery
    • U2 – Vertigo Tour (Rome, Italy)
    • Brighton
    • Amsterdam
    • Athens 2004
    • Holiday Snapshots
  • Portfolio
  • About
  • Contact

Developing HTML Forms in PHP using QuickForm

Display Form

We can display the form on the browser by calling the display() function. This function does not receive any arguments. We use the function in conjunction with the validate() and process() functions.

if(!$form->validate())
{
$form->display();
}
else
{
$form->process(‘on_validate’);
}

The logic that we construct is that if the form does not validate (based on our validation and filtering rules) then the form should be displayed to the browser otherwise the function that handles the submitted data should be called (on_validate($data) on the example).

Default Values

Quickform allows us to specify default values for our form elements. These are values that will populate the fields when the form is being rendered on the browser and can be altered by the user if the element is not frozen (when an element is frozen then its default value is display but the user cannot alter its value).

We can specify default values for a form element by calling the setDefault() function. The function receives an associative array as an argument where the key is the name of the field and its value maps to the value of the element.

The default values approach is an excellent method in populating the fields with values that the user has entered in a previous session.

Process Submitted Values

We have specified what types of elements we want to use, we have specified restrictions that should be applied on the elements, we have set default values on the fields and we have displayed the form on a web page.

The final issue that we need to address is how we process the user submitted values. In ‘Display Form’ section, we specified a callback function that should be called upon successful form submission.

$form->process(‘on_validate’);

We need to define a function that will have one argument which QuickForm will use to pass on the submitted user values.

function on_validate($data)
{
// Do something with $data
}

Bookmark This Page

Add to Buzz Add to Del.icio.us Add to DotNetKicks Add to Facebook Add to Google Bookmarks Add to Mister Wong Add to Tip'd Add to Twitter Add to Yahoo My Web
Hide Sites

Pages: 1 2 3 4

Categories
PHP
Tags
PEAR, PHP
Comments rss
Comments rss
Trackback
Trackback

« A Solid Block of Code is Like a Well Proven Theorem EPIG Add-Ons »

2 Responses to “Developing HTML Forms in PHP using QuickForm”

  1. Trent says:
    June 27, 2006 at 12:35

    Very concise. Thanks, I’ll be using this info!

  2. PEAR QuickForm - Formular mit Validierung (PHP) | SteviesWebsite Blog says:
    May 21, 2009 at 14:40

    [...] Developing HTML Forms in PHP using QuickForm (dountsis.com, en) [...]

Leave a Reply

Click here to cancel reply.

About Dountsis.com

Dountsis.com is the site of the web developer, technology enthusiast, and gadgets addict, Apostolos Dountsis. The articles on this site focus on web development, software and freelance.

Topics

  • EPIG (2)
  • Firefox (6)
  • Funny (1)
  • Programming (3)
  • Site Updates (7)
  • Tutorials (4)
    • .NET (1)
    • PHP (3)
  • Windows (5)
  • WordPress (25)

PayPal Button

If you feel that the open-source projects that I develop and deliver through the site are worth a penny then you could press the button below to send it to me.

Keywords

.NET adblock Bad Sectors C# chkdsk Del.icio.us Eclipse Extension Firefox Hard Disk Microsoft Move Comments PEAR PHP Social Bookmarks Spam User Control Windows Windows XP WinForm WordPress

What I'm Doing...

  • Nite nite 1 week ago
  • RT @JulieMaggot: Τζουλια ΕΕΕΛΑΑΑΑΑ!, Θα κανουμε Σαμπανιαααααααααααα!! #julia_porn 1 week ago
  • My back! Ouch ouch 3 weeks ago
  • More updates...

Recent Articles

  • Social Bookmarks 4.1.2 Point Release
  • How to use User Controls to create MDI WinForm Applications
  • Social Bookmarks Sites Cleanup
  • Social Bookmarks 4.1.1
  • WordPress Plugins Activation Order
  • WordPress Plugin Development

Spam Blocked

65,105 spam comments
blocked by
Akismet
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox