<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>PHP HTML Form Processor Class - Register</title>
<style type="text/css"> body {font-family: tahoma, arial, verdana, sans; font-size: 12px; } </style>
</head>
<body>
<?php
// require the htmlform class
require '../class.htmlform.php';
// instantiate the class
// add a label to the 'firstname' control - used in the template file as {controls.label_firstname}
$form->add('label', 'label_firstname', 'firstname', 'First name:');
// add a text control named "firstname" - used in the template file as {controls.firstname}
$obj =
& $form->add('text', 'firstname');
// set the field as mandatory
$obj->setRule(array('mandatory' => array('e1', 'The above field is required!')));
// add a label to the 'lastname' control - used in the template file as {controls.label_lastname}
$form->add('label', 'label_lastname', 'lastname', 'Last name:');
// add a text control named "lastname" - used in the template file as {controls.lastname}
$obj =
& $form->add('text', 'lastname');
// set the field as mandatory
$obj->setRule(array('mandatory' => array('e2', 'The above field is required!')));
// add a label to the 'email' control - used in the template file as {controls.label_email}
$form->add('label', 'label_email', 'name', 'Email address:');
// add a text control named "email" - used in the template file as {controls.email}
$obj =
& $form->add('text', 'email');
// set the field as mandatory
$obj->setRule(array('mandatory' => array('e3', 'The above field is required!'), 'email' => array('e2', 'Address seems to be invalid!')));
// require a valid email address to be entered
$obj->setRule(array('email' => array('e3', 'Address seems to be invalid!')));
// add a label to the 'password' control - used in the template file as {controls.label_password}
$form->add('label', 'label_password', 'password', 'Choose a password:');
// add a text control named "password" - used in the template file as {controls.password}
$obj =
& $form->add('password', 'password');
// set the field as mandatory
$obj->setRule(array('mandatory' => array('e4', 'Password is required!')));
// also, make the minimum allowed length for the password to be 6 characters
$obj->setRule(array('minlength' => array('6', 'e4', 'The minimum length for passwords is 6 characters')));
// add a label to the 'confirm_password' control - used in the template file as {controls.label_confirm_password}
$form->add('label', 'label_confirm_password', 'confirm_password', 'Confirm password:');
// add a text control named "confirm_password" - used in the template file as {controls.confirm_password}
$obj =
& $form->add('password', 'confirm_password');
// set a rule for this control - it's value must be equal to the value entered in the 'password' field and
// NOTE THAT WE'RE SENDING THE MESSAGE TO TO e4 BLOCK WHERE THE ERROR'S GENERATED BY THE 'password' FIELD ARE ALSO SENT
$obj->setRule(array('compare' => array('password', 'e4', 'Password not confirmed correctly!')));
// generate a CAPTCHA image - used in the template file as {controls.captcha}
$form->add('captcha', 'captcha');
// add a label to the 'captcha_code' control - used in the template file as {controls.label_captcha_code}
$form->add('label', 'label_captcha_code', 'captcha_code', 'Enter the characters you see in the picture:');
// add a text control named "captcha_code" - used in the template file as {controls.captcha_code}
$obj =
& $form->add('text', 'captcha_code');
// validate the entered text only if it's the same as the characters in the CAPTCHA image
$obj->setRule(array('captcha' => array('e5', 'Enter the characters in the picture!')));
$form->add('submit', 'submit', 'Submit');
// validate the form
// code if form is valid
print_r('Form is valid. Do your thing (write to db, send emails, whatever) and redirect.');
die();
}
// display the form with the specified template
$form->render('forms/register.xtpl');
// IF YOU DO NOT NEED ANY SPECIAL FORMATTINGS IN YOUR FORM YOU CAN ALSO CALL THE RENDER METHOD WITHOUT SPECIFYING A TEMPLATE NAME
// AND THUS LETTING THE SCRIPT TO AUTOMATICALLY GENERATE OUTPUT AND SAVING YOU OF EXTRA WORK PUT INTO DESIGNING THE FORM'S LAYOUT
// COMMENT THE LINE ABOVE AND UNCOMMENT THE ONE BELOW TO SEE IT IN ACTION
//$form->render();
?>
</body>
</html>