Example Page for class.form.php

I coded class.form.php for my own use after viewing a similar class online. Feel free to use this script in your projects!

A Simple Form

A simple form to collect email addresses and comments. Only uses the bare minimums.

The Form




The HTML

<form action="example.php" method="post" enctype="multipart/form-data">
<div>
<label class="block" for="email">Email Address</label>
<input type="text" name="email" id="email" /><br />
<label class="block" for="comments">Enter Your Comments</label>
<textarea name="comments" id="comments" cols="" rows=""></textarea><br />
<br />
<input type="submit" />
</div>
</form>

The Code

<?php
include_once('class.form.php');
$form = new genForm;
$form->startForm(basename($_SERVER['PHP_SELF']));
   
$form->textInput('email','Email Address',false,'block');
   
$form->textareaInput('comments','Enter Your Comments',false,'block');
   
$form->insertBR();
   
$form->submitButton();
$form->closeForm();

if(!
$output $form->getForm()) { die("error: " $form->error); }
else { echo 
$output; }
?>

An Advanced Form

This form includes all form elements.

The Form


Gender
Interests






The HTML

<form action="example.php" method="post" enctype="multipart/form-data">
<div>
<label class="block required" for="name">Full Name</label>
<input type="text" name="name" id="name" /><br />
<fieldset>
<legend>Gender</legend>
<input type="radio" name="gender" id="gendermale" value="male" />
<label for="gendermale">Male</label>
<input type="radio" name="gender" id="genderfemale" value="female" />
<label for="genderfemale">Female</label>
</fieldset>
<fieldset>
<legend>Interests</legend>
<input type="checkbox" name="lazy" id="lazy" value="lazy" />
<label for="lazy">Movies</label><br />
<input type="checkbox" name="intellectual" id="intellectual" value="intellectual" />
<label for="intellectual">Reading</label><br />
<input type="checkbox" name="jock" id="jock" value="jock" />
<label for="jock">Sports</label><br />
</fieldset>
<label for="picture">Upload Your Picture</label>
<input type="file" name="picture" id="picture" /><br />
<label class="block" for="about">About You</label>
<textarea name="about" id="about" cols="" rows=""></textarea><br />
<label class="block" for="age">Your Age</label><select name="age" id="age">
<option value="baby">0-3</option>
<option value="toddler">3-5</option>
<option value="child">5-12</option>
<option value="teen">13-19</option>
<option value="adult">20-45</option>
<option value="middleage">45-65</option>
<option value="retiree">65-75</option>
<option value="old">75-95</option>
<option value="stillalive">100+</option>
</select><br />
<br />
<input type="submit" />
<input type="reset" />
</div>
</form>

The Code

<?php
include_once('class.form.php');
$form = new genForm;
$form->startForm(basename($_SERVER['PHP_SELF']));
   
$form->textInput('name','Full Name',false,'block required');
   
$form->startFieldset('Gender');
      
$form->newline false;
      
$form->checkboxInput('radio','gender','male','Male');
      
$form->checkboxInput('radio','gender','female','Female');
      
$form->newline true;
   
$form->closeFieldset();
   
$form->startFieldset('Interests');
      
$form->checkboxInput('checkbox','lazy','lazy','Movies');
      
$form->checkboxInput('checkbox','intellectual','intellectual','Reading');
      
$form->checkboxInput('checkbox','jock','jock','Sports');
   
$form->closeFieldset();
   
$form->fileInput('picture','Upload Your Picture');
   
$form->textareaInput('about','About You',false,'block');
   
$form->startSelect('age','Your Age',false,'block');
      
$form->addOption('baby','0-3');
      
$form->addOption('toddler','3-5');
      
$form->addOption('child','5-12');
      
$form->addOption('teen','13-19');
      
$form->addOption('adult','20-45');
      
$form->addOption('middleage','45-65');
      
$form->addOption('retiree','65-75');
      
$form->addOption('old','75-95');
      
$form->addOption('stillalive','100+');
   
$form->closeSelect();
   
$form->insertBR();
   
$form->newline false;
   
$form->submitButton();
   
$form->newline true;
   
$form->resetButton();
$form->closeForm();

if(!
$output $form->getForm()) { die("error: " $form->error); }
else { echo 
$output; }
?>