PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Emily Brand   phpFormBuilder   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: A sample form to demonstrate the builder
Class: phpFormBuilder
Generate and process HTML forms
Author: By
Last change: changed filename
Date: 14 years ago
Size: 4,070 bytes
 

Contents

Class file image Download
<?php
session_start
();

$_SESSION['page'] = 'index.php'; // Set the current page the form is on.

// Check if new form or submitted one.
if($_POST) {
  include_once(
"process.class.php");
 
$process = new Process($_POST);
  require_once(
"formdisplay.class.php");
 
$form = new FormDisplay("grad");
}
else {
  require_once(
"form.class.php");
 
$form = new Form();
}

if(
$_SESSION['error_array']) {
  echo
"<div style='clear: both; color: red; margin-bottom: 20px;'>Errors have been found with your application: <br />";
  foreach(
$_SESSION['error_array'] as $k => $v) {
    echo
"* $k<br />";
  }
  echo
"</div>";
}

// Start Document.
$content .= $form->text('
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
   <title>Graduate Application For 2010--2011 ExCEL Scholarship</title>
   <style type="text/css">
     /* IF THIS DISPLAYS, PLEASE USE A NEWER BROWSER THAT RECOGNIZES style TAGS. */
     body { margin: 1in; font-size: 14px; width: 8.5in }
     input { margin: 0 5px 0 0px; }
     label {padding: 0 5px 0 0px; }
     .boxed { border: solid 1px }
     img { padding: 3px; margin: 2px }
     input[type="submit"] { text-align: center; margin: 0px auto; padding: 3px; display: block; cursor: pointer;}
   </style>
   </head>
  
  <body>
'
);

$content .= $form->text("<form name='grad' action='sample.php' method='post'>");
$content .= $form->text("<h3 style='clear: both'>Autobiographical Information</h3>");

$content .= $form->createTextBox("Name: ", "name", $form->value("name"), 30, 200);
$sex = array("Male " => "male", "Female " => "female");
$content .= $form->createRadioButton($sex, "sex", $form->value("sex"));
$content .= $form->createTextBox("Born: Month: ", "birthmonth", $form->value("birthmonth"), 2, 2);
$content .= $form->createTextBox("Day: ", "birthday", $form->value("birthday"), 2, 2);
$content .= $form->createTextBox("Year: ", "birthyear", $form->value("birthyear"), 4, 4);

$content .= $form->linebreak();
$content .= $form->text("United States: ");
$citizen = array("Citizen or National " => "citizen", "Lawful Permanent Resident " => "resident");
$content .= $form->createRadioButton($citizen, "citizen", $form->value("citizen"));

$content .= $form->linebreak();
$content .= $form->text("Ethnic Background (Optional): ");
$ethnicity = array("Asian " => "asian", "African-American " => "african",
                   
"Caucasian " => "caucasian", "Hispanic " => "hispanic",
                   
"Multiracial " => "multiracial", "American Indian or Alaskan Native " => "indianalaskan",
                   
"Puerto Rican " => "puertorican", "Native Hawaiian or Pacific Islander " => "pacific",
                   
"Other " => "other",);
$content .= $form->createRadioButton($ethnicity, "ethnicity", $form->value("ethnicity"));

$content .= $form->linebreak();
$content .= $form->text("Permanent Address: ");
$content .= $form->createTextBox("Number and Street: ", "street", $form->value("street"), 70, 80);
$content .= $form->text("<br />");
$content .= $form->createTextBox("City: ", "city", $form->value("city"), 42, 42);
$content .= $form->createTextBox("State: ", "state", $form->value("state"), 2, 2);
$content .= $form->createTextBox("Zip: ", "zip", $form->value("zip"), 5, 5);

$content .= $form->linebreak();
$content .= $form->createTextBox("Home Phone: ", "homephone", $form->value("homephone"), 10, 15);
$content .= $form->createTextBox("Cell Phone: ", "cellphone", $form->value("cellphone"), 10, 15);
$content .= $form->createTextBox("E-mail address: ", "email", $form->value("email"), 40, 60);

$content .= $form->createSubmit("submitForm", "Submit Your Application");

$content .= $form->text("</form> ");

$content .= $form->text("</body> </html> ");

echo
$form->finalizeForm($content);