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

A Working Example

The following example displays a contact form, that require a name and a message to be entered. The email address is an optional field, but if the user decides to submit one then we make sure that we receive an email address in the correct format (xxxx@xxxx.xxx).

require('HTML/QuickForm.php');
// general purpose library functions
include_once('common.php');

$form =& new HTML_QuickForm(‘contact’);

// The form elements
$form->addElement(‘html’, ‘Use the form below to contact me.’);
$form->addElement(‘header’, ‘contact_header’, ‘Contact Form’);
$form->addElement(‘text’, ‘contact_name’, ‘Your name:’);
$form->addElement(‘text’, ‘contact_email’, ‘Your e-mail address:’);
$form->addElement(‘textarea’, ‘contact_body’, ‘Your message:’);
$form->addElement(’submit’, ’submit_button’, ‘Send’);

// Validation rules
$form->addRule(‘contact_email’,
‘Please specify a valid email address’, ‘email’);
$form->addRule(‘contact_name’,
‘Please enter your name’, ‘required’);
$form->addRule(‘contact_body’,
‘Please enter some text’, ‘required’);

// Display the form if validation fails
// otherwise call on_validate()
if(!$form->validate())
{
$form->display();
}
else
{
$form->process(‘on_validate’);

}

// The function the processes the submitted values
function on_validate($data)
{
print(‘You have entered the following:’);
pre_print_r($data);
}
?>

Example in action

In the next article, we will be concentrating on how we can make use of QuickForm to upload a file and how we can group elements together like radio boxes.

Rate This Page

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4.00 out of 5)
Loading ... Loading ...
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