Login   Register  
PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Bulent Tezcan  >  AdvancedForm  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: this is your documentation and demo file
Class: AdvancedForm
Generate forms inside a table, which supports CSS.
Author: By
Last change: name change in guinness.css
Date: 2002-06-14 06:36
Size: 17,122 bytes
 

Contents

Class file image Download
<?
	require "Form.class.php";

	session_start( );

	
	if (!isset($_SESSION['cssName']))
		$_SESSION['cssName'] = "Corona";
	
	if (!isset($_SESSION['numberOfColumns']))
		$_SESSION['numberOfColumns'] = 2;

	$cssForm = $_POST['form_cssForm'];

	if (!$cssForm['cssName'])
		$cssForm['cssName'] = $_SESSION['cssName'];

	if ($cssForm['cssName'])
		$_SESSION['cssName'] = $cssForm['cssName'];

	if (!$cssForm['numberOfColumns'])
		$cssForm['numberOfColumns'] = $_SESSION['numberOfColumns'];

	if ($cssForm['numberOfColumns'])
		$_SESSION['numberOfColumns'] = $cssForm['numberOfColumns'];

	?>
	<html>
	<head>
		<link rel="stylesheet" type="text/css" href="themes\Moosehead.css">
		<link rel="stylesheet" type="text/css" href="themes\Carling.css">
		<link rel="stylesheet" type="text/css" href="themes\Coors.css">
		<link rel="stylesheet" type="text/css" href="themes\CoorsLight.css">
		<link rel="stylesheet" type="text/css" href="themes\Carlsberg.css">
		<link rel="stylesheet" type="text/css" href="themes\LabattBlue.css">
		<link rel="stylesheet" type="text/css" href="themes\Guinness.css">
		<link rel="stylesheet" type="text/css" href="themes\Corona.css">
		<link rel="stylesheet" type="text/css" href="themes\Pilsner.css">
	</head>
	<?
	?><body class="<?=$cssForm['cssName']?>PageBODY"><?
	
	echo "<style type=\"text/css\">";
	echo "P{font-family : Verdana, Tahoma, Arial, Helvetica; font-size : 13px;}";
	echo "P:first-letter{font-size:150%; float:left}</style>";

	echo "<div style='margin-left:.5in; background:#F9F6EC; border:dotted .5pt;padding:1.0pt 4.0pt 1.0pt 4.0pt'>";

	#echo "<div class=\"". $cssForm['cssName'] ."FormTABLE\">";
	
	echo "<p>This demo shows you how to create forms in an Object Oriented way, so simple and elegant.</p><p>You can create multiple forms in the same page with exactly the same form element names, without worrying the names.<br>Because each form will return to you as an array, you don't have to worry about the names being used or not.<p>You can create select boxes from a database input with a minimum line of code.<p>You can insert more than one form under one form name.<p>The options are endless, it is limited with your imagination, and creativity.<p>Not only you will reduce the time of developing, you will have a nicer code without any cumbersome HTML code inside of your PHP code.<p>Using the CSS you can change the look and feel of your forms just in seconds.<p>To see how you can change the color of your form select from the predefined CSS down below. You can always create your own styles to match with your site colors.</div>";

	echo "<h3><center>This is the table format of the class Form</center></h3>";

	#
	# Here we set some of the values for the form and the table
	# that the form is going to be in. You can use predefined CSS
	# for ease of use or create your own.
	#
	$myForm2 = new Form("cssForm");
	$myForm2-> SetNumberOfColumns( 2 );
	$myForm2-> SetCellSpacing( 1 );
	$myForm2-> SetCellPadding( 4 );
	$myForm2-> SetBorder	( 0 );
	$myForm2-> SetAlign ("center");
	$myForm2-> SetTableWidth ("400");
	$myForm2-> SetTableHeight (null);
	$myForm2-> SetCSS ($cssForm['cssName']);
	$myForm2-> SetEmptyCells (true);
	$myForm2-> SetFormHeader("Please Select a Style");
	# you can show your messages with this method at the top of the form.
	
	$myForm2-> SetErrorMessage("");
	
	# we directly add a label into the form
	
	$myForm2-> AddFormElement(new Label($name="lbl1",$value="Please Select a CSS :"));

	# create an array, so we can pass it to the SelectBox class to be displayed.
	# See how easy it is to create it. You can read the values from a database
	# create an array, and pass it to the class, thats all there is to it to
	# create a select box from a database table.
	
	$cssArray = array();
	
	array_push($cssArray,"Corona");
	array_push($cssArray,"Carling");
	array_push($cssArray,"Coors");
	array_push($cssArray,"CoorsLight");
	array_push($cssArray,"Carlsberg");
	array_push($cssArray,"Moosehead");
	array_push($cssArray,"LabattBlue");
	array_push($cssArray,"Guinness");
	array_push($cssArray,"Pilsner");

	# create a selectBox object called CSS. You can pass extra things like
	# javascript on certain events.
	
	$CSS = new SelectBox($name="cssName",$values=$cssArray,$selected=$cssForm['cssName'],$default="-Please Select a CSS-",$displayOnly=false,$size=0,$multiple=FALSE,
	$extra="onchange=\"javascript:this.form.submit();\"");

	# if you want your select box elements to have different color
	# you can use this method.

	$CSS-> SetZebraColor($color="#C0C0C0");
	
	# What this means, when you select a value from the selectbox, it will return
	# the text you see in that select box. If you don't set this, default is the
	# index sequence, like 0=>Carling, 1=>bla, 2=>bla_bla
	
	$CSS-> SetReturnValueAsText( );

	# add the select box into the form
	
	$myForm2-> AddFormElement($CSS);
	
	# we directly add a label into the form

	$myForm2-> AddFormElement(new Label($name="lbl2",$value="Please enter a number<br>to set the number of columns <br>to be displayed for the table:"));
	
	# we directly add a textfield into the form
	
	$myForm2->	AddFormElement	(new TextField($name="numberOfColumns",$value=$cssForm['numberOfColumns'],$size=2,$maxLength=2,$displayonly=false));
	
	# lets add some buttons to our form
	
	$buttons = new ObjectArray("buttons"); 
	$buttons->AddObject(new SubmitButton( $name="Submit",$value="Submit"));
	$buttons->AddObject(new ResetButton( $name="Reset",$value="Reset"));
	
	# we want the buttons in one cell and aligned middle
	
	$buttons->SetCellAttributes(array("align"=>"middle"));
	
	# if you want to span your object into multiple columns, please use this
	# method.
	
	$buttons->SetColSpan(2);
	
	$myForm2->	AddFormElement	($buttons); 
	
	# thats how we show the form.

	echo $myForm2-> GetFormInTable();




	# this is the second form you see
	# -------------------------------

	$myForm = new Form( "myTestForm" );

	#
	# Here we set some of the values for the form and the table
	# that the form is going to be in. You can use predefined CSS
	# for ease of use or create your own.
	#

	$myForm-> SetNumberOfColumns( $cssForm['numberOfColumns'] );
	$myForm-> SetCellSpacing( 1 );
	$myForm-> SetCellPadding( 4 );
	$myForm-> SetBorder	( 0 );
	$myForm-> SetAlign ("center");
	$myForm-> SetTableWidth ("500");
	$myForm-> SetTableHeight (null);
	$myForm-> SetCSS ( $cssForm['cssName'] );
	$myForm-> SetEmptyCells (true);
	$myForm-> SetFormHeader("Demonstration Form");
	# You can set the error message at any time. It will appear at the top 
	# of the table.
	
	$myForm-> SetErrorMessage("This form demonstrates what you can do with your form elements, how you can change the colors or positions, how you can create select boxes, radio buttons, submit buttons etc. and get the form in a nicly created table.");
	

	# we directly add a label into the form
	
	$myForm->	AddFormElement	(new Label($name="label1",$value="An ordinary Label:"));
	
	# Create an instance of a textfield object
	
	$fname = new TextField($name="firstname",$value="I am a text field with displayonly attribute set to TRUE.",$size=15,$maxLength=35,$displayonly=true);
	
	# Now we add the textfield object into our form
	
	$myForm->	AddFormElement	($fname);

	# Create an instance of the object label
	
	$lastName = new Label("label2","My neighbour is a textbox with a max input limit set to 35, but it shows only the first 20 characters.");

	# Add the label object into our form
	
	$myForm->	AddFormElement	($lastName);

	# Add a textfield object directly into our form 
	
	$myForm->	AddFormElement	(new TextField($name="lastname",$value="TextField width=20 maxlength=35",$size=20,$maxLength=35,$displayonly=false));
	
	# Add a label into the form
	
	$myForm->	AddFormElement	(new Label($name="label3",$value="Occupation   :"));
	
	# Add another textfield object with a value of blank ""
	
	$myForm->	AddFormElement	(new TextField($name="occupation",$value="",$size=20,$maxLength=35,$displayonly=false));
	
	#
	# You can create an array of objects. Add all the objects into the
	# array. And than add the array into your form.
	#
	# Because each object goes into its own table cell, and we want
	# multiple objects to appear in the same cell, we do this little trick.
	#

	$CheckBoxOptions = new ObjectArray("someoptions");
	
	# create an instance of object CheckBox. If you want to set the
	# displayonly attribute to true, you will need a gif or jpeg image
	# that will look like a checkbox. Don't worry, we will provide that
	# as well.

	$checkBoxOption1 = new CheckBox($name="option1",$value="1",$IsChecked,$displayOnly=false,
	$displayText="Option-1 :");
	
	$checkBoxOption2 = new CheckBox($name="option2",$value="2",$IsChecked,$displayOnly=false,
	$displayText="Option-2 :");

	# add each of the objects into our array of objects.Now our array
	# contains two checkboxes.
	
	$CheckBoxOptions->AddObject($checkBoxOption1);
	$CheckBoxOptions->AddObject($checkBoxOption2);

	#
	# Because $radio_buttons is an ObjectArray, they return no CSS.
	# So if you want to set a style for ObjectArrays 
	# drop the name of the CSS and pass the rest of it.
	# If you look at the CSS you'll understand Coorsly.

	$CheckBoxOptions->SetClass("DataTD");

	# create the label
	
	$myForm->	AddFormElementToNewLine	(new Label($name="label1",$value="Check Boxes :"));
	
	# add the array with two checkboxes into our form
	
	$myForm->	AddFormElement	($CheckBoxOptions);

	# create the label
	
	$myForm->	AddFormElementToNewLine	(new Label($name="label1",$value="Check Box images you need when you set the displayonly property to true :"));

	# create image objects
	$image1 = new PassTru("<img src='http://www.greenpepper.ca/images/unchecked.gif' border=0 alt=''>&nbsp;&nbsp;");
	$image2 = new PassTru("<img src='http://www.greenpepper.ca/images/checked.gif' border=0 alt=''>");

	# create array of objects
	$images = new ObjectArray("images");
	$images-> SetClass("DataTD");
	
	# add each object to the array
	$images-> AddObject($image1);
	$images-> AddObject($image2);

	# now display the array of objects
	$myForm->	AddFormElement	($images);

	# Radio buttons are a bit different than the checkboxes. They could be
	# part of a same group. For example sex, could be male or female (thats what
	# I know anyways). So the following example shows how to do it.
	# 
	# So it is a radio button group and we want to see them vertically.
	$iRadioButton2 = new RadioButton($name="sex",$vertical=true,$displayOnly=false);
	
	$iRadioButton2->AddOption($label="Male:",$value="m",$IsChecked=FALSE);
	$iRadioButton3 = new RadioButton($name="sex",$vertical=true,$displayOnly=false);
	$iRadioButton3->AddOption($label="Female:",$value="f",$IsChecked=FALSE);
		
	$radio_buttons = new ObjectArray($name="radio_buttons");
	$radio_buttons->AddObject($iRadioButton2);
	$radio_buttons->AddObject($iRadioButton3);

	# we set the cell attribute to align right. This is always
	# an array. You can define as many attributes as you want, just pass them
	# as an array at once. array("align"=>"right","color"=>"#ffcc33")

	$radio_buttons->SetCellAttributes(array("align"=>"left"));

	#
	# Because $radio_buttons is an ObjectArray, they return no CSS.
	# So if you want to set a style for ObjectArrays 
	# drop the name of the CSS and pass the rest of it.
	# If you look at the CSS you'll understand Coorsly.

	$radio_buttons->SetClass("DataTD");

	# add a new label
	
	$myForm->	AddFormElementToNewLine	(new Label($name="label1",$value="We are all the same group of radio buttons, displayed vertically and aligned left"));
	
	# add all the radio buttons into the form. This way we will see them
	# in a single table cell
	
	$myForm->	AddFormElement	($radio_buttons);

	# add a new label
	
	$myForm->	AddFormElementToNewLine	(new Label($name="label6",$value="Country:"));
	

	# create an array of countries. This will be the values for the
	# select box.

	$country = array(0=>"Canada","Colombia","Spain","Turkey","Zimbabve");
	
	# Now create a select box object and add it to the form.
	# You can see how easy to create select boxes. If you have a database
	# driven website all you have to do is read the information from the
	# database create an array and feed the array to the SelectBox object.
	
	$countries = new SelectBox($name="countries",$values=$country,$selected=0,$default="-Please Select a country-",$displayOnly=false,$size=0,$multiple=FALSE,
	$extra="");
	
	# this will set a background color every after two times (unless you set it
	# to something else) for each element in the select box.

	$countries-> SetZebraColor($color="#FFCC00");

	# this is optional, you don't have to use it, default is two.
	
	$countries-> SetZebraColorEveryNtimes( 2 );

	# now add the selectbox into the form
	
	$myForm-> AddFormElement ($countries);

	# add another label
	
	$myForm->	AddFormElement	(new Label($name="label7",$value="Comments:"));

	# now we create a TextArea object

	$textArea = new TextArea($name="comment",$value="My CSS Class is: WhiteOnBlack",$rows=3,$cols=25,$displayOnly=false);

	# now we set the textarea object's CSS class to something different
	# than the form's CSS. This way we can mix match different styles in the
	# same form.

	$textArea->SetClass("WhiteOnBlack");

	# now add the textarea object into the form.

	$myForm-> AddFormElement ($textArea);
	
	# add another label
	
	$myForm->	AddFormElement	(new Label($name="label8",$value="Secret code:"));
	
	# add a password field to the form

	$myForm-> AddFormElement (new Password($name="secretcode",$value="secret",$size=10,$maxlength=10,$extra=""));
	
	# create a label
	
	$myForm-> AddFormElementToNewLine (new Label($name="label2",$value="Actions :<br>Those values are coming from a database table"));

	$getoptions = new GetOptions($name="actionid",$table="actions",$field="actionname",$key="actionid",$extraSql="ORDER BY actionname", $selected=$FormElements["actionid"], $default="-Select an action-",  $displayonly=$this->mDisplayOnly, $size=0,$muliple=FALSE,$extra="");
	
	$myForm->	AddFormElement	($getoptions); 


	# create a label
	
	$testLabel = new Label($name="label2",$value="I am a Label and have a different CSS class than the rest of the form elements");
	
	# set the class to something else just to be different than the rest
	
	$testLabel->SetClass("SomethingBright");

	# add the label to the form
	
	$myForm-> AddFormElement ($testLabel);
	
	# add a filler cell to the form
	
	$myForm-> AddFormElement (new Dummy( ));

	# Now we introduce a new feature, AddFormElementToNewLine. This allows you
	# to force the program to add the new element to a new row rather than
	# to a next cell.

	# the only thing you should set is that if you want empty cells or not.
	# you can do it by	$myForm-> SetEmptyCells (true/false);
	# Netscape doesn't show nicly if you dont put empty cells. You can also
	# put the empty cells manually if you want.
	# Than you should add an empty cell like 
	# $myForm-> AddFormElement (new Dummy());
	
	$myForm->	AddFormElementToNewLine	(new Label($name="label9",$value="What files are you sending?"));
	
	# add a fileupload button
	
	$myForm-> AddFormElement (new InputFile($name="uploadfile"));
	
	# lets add some buttons to our form
	
	$buttons = new ObjectArray("buttons"); 
	$buttons->AddObject(new SubmitButton( $name="Submit",$value="Submit"));
	$buttons->AddObject(new ResetButton( $name="Reset",$value="Reset"));
	
	#$buttons->AddObject(new Button( $name="Cancel",$value="",$type="button",$extra="",$image="/images/red.gif"));
	
	# we want the buttons in one cell and aligned middle
	
	$buttons->SetCellAttributes(array("align"=>"middle"));
	
	# if you want to span your object into multiple columns, please use this
	# method.
	
	$buttons->SetColSpan($cssForm['numberOfColumns']);

	$myForm->	AddFormElementToNewLine	($buttons);
	
		
	$buttons2 = new ObjectArray("buttons2");
	$b1 = new SubmitButton( "B1","<<");
	$b1->SetClass("SmallButton");
	$buttons2->AddObject($b1);
	$b2 = new SubmitButton( "B2",">>");
	$b2->SetClass("SmallButton");
	$buttons2->AddObject($b2);
	$b3 = new SubmitButton( "B3","|>");
	$b3->SetClass("SmallButton");
	$buttons2->AddObject($b3);
	$buttons2->SetCellAttributes(array("align"=>"middle"));
	
	# if you want to span your object into multiple columns, please use this
	# method.
	
	$buttons2->SetColSpan($cssForm['numberOfColumns']);

	$myForm->	AddFormElementToNewLine	($buttons2);

	
	# You have two options here. You can get the form in a table or just plain
	# as it is. The function will return you the HTML string. So you have
	# to print it before you can see it.
	
	echo $myForm->GetFormInTable( );
	

	?>
	</body>
	</html>
	<?
	return true;
?>