I would go further and totally recreate the way forms are generated in phpBB.
A very good solution is having a form defined through an object interface in the PHP files, from which hooking up validation (both JS and PHP) could be deployed.
An example from one other project:
You can just assign $form to a template variable and output it in the templates. Another method in the processing script handles the data passed.
Code: Select all
$form = new Form(); $form->addText('name', 'Your name:') ->addRule(Form::FILLED, 'Enter your name'); $form->addText('age', 'Your age:', 5) ->addRule(Form::FILLED, 'Enter your age') ->addRule(Form::NUMERIC, 'Age must be numeric') ->addRule(Form::RANGE, 'Age must be in range from %d to %d', array(10, 100)); $form->addCheckbox('send', 'Shipping address:') ->addCondition(Form::EQUAL, TRUE); $form->addText('email', 'Email:', 35) ->setEmptyValue('@') ->addCondition(Form::FILLED) // conditional rule: if is email filled, ... ->addRule(Form::EMAIL, 'E-mail is not valid'); // ... then check email