PHP Form Builder Class / Examples / Layout

Version: Released:

Layout - The project's default layout will render each element on it's own line, place the labels above the elements, and set the elements' widths to span the entire length of the form. Below, you'll find several form/element attributes that can be used to alter your forms' layouts.

Below are several example forms that demo many of the attributes listed above.

Processing

<?php
$form 
= new form("layout_0");
$form->setAttributes(array(
    
"width" => 500,
    
"map" => array(2213)
));

if(!empty(
$_GET["errormsg_0"]))
    
$form->errorMsg filter_var(stripslashes($_GET["errormsg_0"]), FILTER_SANITIZE_SPECIAL_CHARS);

$form->addHidden("cmd""submit_0");
$form->addTextbox("First Name:""FName");
$form->addTextbox("Last Name:""LName");
$form->addEmail("Email Address:""Email");
$form->addTextbox("Phone Number:""Phone");
$form->addTextbox("Address:""Address");
$form->addTextbox("City:""City");
$form->addState("State:""State");
$form->addTextbox("Zip Code:""Zip");
$form->addButton();
$form->render();
?>
Processing

<?php
$form 
= new form("layout_1");
$form->setAttributes(array(
    
"width" => 400,
    
"labelWidth" => 100,
    
"labelPaddingTop" => "0.5em"
));

if(!empty(
$_GET["errormsg_1"]))
    
$form->errorMsg filter_var(stripslashes($_GET["errormsg_1"]), FILTER_SANITIZE_SPECIAL_CHARS);

$form->addHidden("cmd""submit_1");
$form->addTextbox("Username:""Username""", array("required" => 1));
$form->addPassword("Password:""Password""", array("required" => 1));
$form->addHTML('<a href="#">Forgot your password?</a>');
$form->addButton("Login");
$form->render();
?>
Processing

<?php
$form 
= new form("layout_2");
$form->setAttributes(array(
    
"width" => 800,
    
"labelWidth" => 125,
    
"labelRightAlign" => 1,
    
"labelPaddingTop" => "0.5em",
    
"map" => array(2213)
));

if(!empty(
$_GET["errormsg_2"]))
    
$form->errorMsg filter_var(stripslashes($_GET["errormsg_2"]), FILTER_SANITIZE_SPECIAL_CHARS);

$form->addHidden("cmd""submit_2");
$form->addTextbox("First Name:""FName""", array("required" => 1));
$form->addTextbox("Last Name:""LName""", array("required" => 1));
$form->addEmail("Email Address:""Email""", array("required" => 1));
$form->addTextbox("Phone Number:""Phone");
$form->addTextbox("Address:""Address");
$form->addTextbox("City:""City");
$form->addState("State:""State");
$form->addTextbox("Zip Code:""Zip");
$form->addButton();
$form->render();
?>
Processing

<?php
$form 
= new form("layout_3");
$form->setAttributes(array(
    
"width" => 400,
    
"noAutoFocus" => 1,
    
"preventJQueryLoad" => 1,
    
"preventJQueryUILoad" => 1,
    
"labelWidth" => 100,
    
"labelPaddingTop" => "0.5em",
    
"labelDisplayRight" => 1
));

if(!empty(
$_GET["errormsg_3"]))
    
$form->errorMsg filter_var(stripslashes($_GET["errormsg_3"]), FILTER_SANITIZE_SPECIAL_CHARS);

$form->addHidden("cmd""submit_3");
$form->addTextbox("Username:""Username""", array("required" => 1));
$form->addPassword("Password:""Password""", array("required" => 1));
$form->addHTML('<a href="#">Forgot your password?</a>');
$form->addButton("Login");
$form->render();
?>