FormP

What is FormP?

FormP is a simple form processor based on Savant's templating system. Currently, Savant is the only templating system the form processor will work with, but other templating systems could easily be modified to support FormP.

FormP handles only the processing logic of the form. It does not handle displaying the form, as this is the job of the templating engine.

THIS PROJECT IS WORK IN PROGRESS

Please please do send me feedback.

Working example http://pookey.co.uk/formp/index.php

View the code at http://pookey.co.uk/formp/index.phps

A basic form might look like this

    class MyForm extends SavantForm {
 
        function __construct() {
            $this->addElement(array('label'     => 'Username',
                                    'name'      => 'Username',
                                    'type'      => 'text',
                                    'require'   => true,
                                    'attribs'   => array('size' => '30')));
            $this->addElement(array('label'     => 'Password',
                                    'name'      => 'Password',
                                    'type'      => 'password',
                                    'require'   => 'A password is required'));
            $this->addElement(array('label'     => 'Password Again',
                                    'name'      => 'Password1',
                                    'type'      => 'password'));
            $this->addElement(array('name'      => 'ClearUsername',
                                    'type'      => 'submit',
                                    'value'     => 'Clear Username',
                                    'persistant' => false,
                                    'onClick'   => array(&$this, 'ClearUsername')));
            $this->addElement(array('name'      => 'Reset',
                                    'type'      => 'reset',
                                    'value'     => 'Reset Form',
                                    'persistant' => false,));
            $this->addElement(array('name'      => 'Submit',
                                    'type'      => 'submit',
                                    'value'     => 'Submit',
                                    'persistant' => false,
                                    'onClick'   => array(&$this, 'Process')));
            $this->addValidationRule('Password', SavantForm::VALIDATION_CALLBACK, '', array(&$this, 'CheckPassword'));
            $this->addValidationRule('Username', SavantForm::VALIDATION_REGEX, 'A username must be more then 6 chars', '/[a-z]{6,}/');
        }
 
        function CheckPassword () {
            if ($this->getValue('Password') != $this->getValue('Password1')) {
                return "Passwords must match";
            }
            return true;
        }
 
        function ClearUsername () {
            $this->setValue('Username', '');
        }
 
        function Process() {
            // this is run when the submit button is clicked
        }
    }

The template file simply has this in it

<html>
 
<head>
    <title>Autogen form test</title>
</head>
 
<body>
    <h3>Automatic form test</h3>
    <?= $this->form('begin'); ?>
    <?= $this->form('auto', $this->form); ?>
    <?= $this->form('end'); ?>
</body>
 
</html>