Source code in QfSimple.php

To see how this is used return to this tutorial index.

    // A simple quickform. Return to this tutorial index to see it working.

    // Copyright (c) 2005, 2013 Parliament Hill Computers ( Author: Alain D D Williams (
    // You may used this file as the basis your own (or organisation's/company's) project (under whatever
    // licence that you see fit), but may not claim ownership or copyright of the substantially unmodified file.
    // This file is made available in the hope that it is useful, there is no warranty at all, use at your own risk.
    // SCCS: @(#)QfSimple.php	1.7 11/15/13 11:31:59
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <title>Quickform Demo</title>
   <link rel="stylesheet" type="text/css" href="/DefaultStyle.css">

  <!-- A standard page header -->
  <div style='position : absolute;text-align: left;top:10px;'>
   <a href='/'><img src='/Images/kite_40_83_trans.gif' width="40" height="83" alt="Parliament Hill Computers Ltd" style="border-width: 0;"></a>
  <div style='top:0px;margin:0px auto;text-align: center; font-size:40pt; '>
   Simple Quickform


    // Stop warnings due to HTML_Quickform being stuck at PHP4
    if($ini_val = ini_get('error_reporting'))
        ini_set('error_reporting', ($ini_val & ~(E_STRICT | E_DEPRECATED)));

    require_once "HTML/QuickForm.php";

    // Create a GET form with the name QfDemo:
    $form = new HTML_QuickForm('QfDemo', 'get');

    // addElement() adds a display line or an input field to the form.
    // The first argument is a standard html type (text, checkbox, hidden, ...) or a custom
    // type (header, group, ...). Other arguments depend on the type.
    $form->addElement('header', 'DemoHeader', 'Quickform Demo');

    // Add a drop down select list:
    $form->addElement('select', 'Title', 'Title', array('Mr', 'Mrs', 'Miss', 'Dr'));

    // Add a text field, the form element name is 'FirstName' with a title 'First name':
    $form->addElement('text', 'FirstName', 'First name');

    // A few other fields:
    $form->addElement('text', 'LastName', 'Last name');
    $form->addElement('text', 'Age', 'Age');
    $form->addElement('text', 'Telephone', 'Telephone number');

    // Standard buttons:
    $form->addElement('reset', 'Clear', 'Clear');
    $form->addElement('submit', 'Submit', 'Submit');

    // First time round this results in false, remember that, as is common in php, this
    // script is used both to generate the form and to process the results.
    if ($form->validate()) {
        # Get here when the form has been filled in
	// $form->freeze();	// If we want the form redisplayed in the way that the user entered it
				// but you need to do another display()
	$res = $form->exportValues();

        // No validation is done, so the fields could contain anything or just not be there.
        if(isset($res['Title']) && isset($Titles[$res['Title']]))
	    echo "Title = " . htmlspecialchars($res['Title']) . " = '" . $Titles[$res['Title']] . "'<br>\n";

	    echo "FirstName = " . htmlspecialchars($res['FirstName']) . "<br>\n";

	    echo "LastName = " . htmlspecialchars($res['LastName']) . "<br>\n";

	    echo "Age = " . htmlspecialchars($res['Age']) . "<br>\n";

	    echo "Telephone = " . htmlspecialchars($res['Telephone']) . "<br>\n";
    } else {
    	// First time display the form

   This is a simple form, fill in some values and press <i>Submit</i>.

  <p style="font-size: x-large; font-weight: bold;">
   Return to this <em><a href='index.php'>tutorial index</a></em>.


Return to this tutorial index.