Login   Register  
PHP Classes
elePHPant
Icontem

File: ex_form.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Le Régent Frédéric  >  form utils  >  ex_form.php  >  Download  
File: ex_form.php
Role: ???
Content type: text/plain
Description: sample page
Class: form utils
Author: By
Last change:
Date: 2002-03-26 17:49
Size: 5,556 bytes
 

Contents

Class file image Download
<?
require("class.forms.php");
require("def.form.php");
/* ******************
	init form		*/
$sform	= new Form("subscribeForm");
/*
	init all fields
	fCreateField(LabelField, LabelError, FieldName, TypeField, Min value, Max value, Mandatory, false=radio, true=checkbox Only for group field)*/
$sform->fCreateField("Your Last Name", 	"\"Last Name\"", 	"lname",		"TEXT_FIELD",	10,100,true,"");
$sform->fCreateField("Your Fisrt name", "\"first Name\"",	"fname",		"TEXT_FIELD",	1,100,true,"");
$sform->fCreateField("Your Message", 	"\"Message\"", 	"message",	"TEXT_FIELD",	1,100,true,"");
$sform->fCreateField("Your Email", 	"\"Email\"", 		"email",		"EMAIL_FIELD",	1,500,true,"");
$sform->fCreateField("Your country", 	"\"Country\"", 	"country",	"GROUP",		1,1,true,"");
$sform->fCreateField("Newsletter", 	"\"Newsletter\"",	"mlist",		"GROUP",		2,3,false,false);
$sform->fCreateField("Your Birthdate", 	"\"Birthdate\"", 	"birth",		"DATE_FIELD",	1900,2000,false,"");

/* *****************************
	Add local format for date */
$sform->DefaultDateType	= "d/m/y";
$sform->DefaultDateLib	= "Day/Month/Year";

/* *********************************
	Add local error messages
	$sform->ERRFormMain		= "This form contain error";
	$sform->ERRFormfieldEmpty	= "[fieldname] field is empty";
*/

/* *******************************************
	Add all country's values (def.form.php) */
	$sform->faddOption("country","","Select your country");
	while (list ($key, $val) = each ($allCountries)) {
		$sform->faddOption("country",$key,$val);
	}

/* ****************************
	Add values to GROUP field
	faddOption(FieldName, Key, Value)
	*/
	$sform->faddOption("mlist","yes","Yes");
	$sform->faddOption("mlist","no","No");

/* ********************
	Add default value
	fAddDefault(FieldName, Value)
	*/
	$sform->fAddDefault("lname","your name");
	$sform->fAddDefault("mlist","no");
	$sform->fAddDefault("mlist","yes");
	$sform->fAddDefault("mlist","yes");
	$sform->fAddDefault("birth","01/01/1976");	/* this format date need like "DefaultDateType" */

/* ********
	Add Handler to field
	faddHandles(FieldName,Handler,Value)
	Apply style, javascript control
	*/
	$sform->faddHandles("lname",	"style","font: 11px Verdana; color : #000000; background-color : #D6DEF7; height:20px; width:200px");
	$sform->faddHandles("fname",	"style","font: 11px Verdana; color : #000000; background-color : #D6DEF7; height:20px; width:200px");
	$sform->faddHandles("fname",	"onclick","alert(this.value);");
	$sform->faddHandles("message","style","font: 11px Verdana; color : #000000; background-color : #D6DEF7; height:100px; width:300px");
	$sform->faddHandles("email",	"style","font: 11px Verdana; color : #000000; background-color : #D6DEF7; height:20px; width:200px");
	$sform->faddHandles("country","style","font: 11px Verdana; color : #000000; background-color : #D6DEF7; height:200px; width:200px");
	$sform->faddHandles("mlist",	"style","font: 11px Verdana; color : #000000; background-color : #D6DEF7; height:20px; width:50px");
	$sform->faddHandles("birth",	"style","font: 11px Verdana; color : #000000; background-color : #D6DEF7; height:20px; width:60px");

/* ***********************
	Custom Visual items
	<%source%> is Label error
	*/
	$sform->StyleField['mandatory']	= "<font size=\"2\" face=\"Verdana\" color=\"\"><b><%source%>&nbsp;*</b></font>";
	$sform->StyleField['nomandatory']	= "<font size=\"2\" face=\"Verdana\" color=\"\"><%source%>&nbsp; (optional)</font>";
	$sform->StyleField['error']		= "<font size=\"2\" face=\"Verdana\" color=\"red\"><b><%source%>&nbsp;*</b></font>";

	// Valid this form
	$sform->fValidForm($HTTP_POST_VARS);

?>
<html>
	<head>
	</head>
	<body>
	<?
	/*
		Display all error*/
	if ($sform->ListErrMsg<>"") {
		/* Write Main Label error*/
		echo $sform->ERRFormMain."<br>";

		/* Write others errors*/
		while (list ($key ,$val) = each ($sform->ListErrMsg)) {
			echo $sform->ListErrMsg[$key]."<br>";
		}
	}
	?>

	<br>
	<?
	/* ********************
		Display Tag Form
		In this sample, fToTag return "<form name="" action="POST" onsubmit=" return do_valid();">"*/
	echo $sform->fToTag("do_valid()");
	?>

	<?
	/*
		Display Label field*/
	echo $sform->fVisualName("lname")?><br>

	<?
	/* *************
		Build field
		fToField(FieldName, Size)		= type text
		fToField(FieldName, Size)		= type hidden
		fToSelect(FieldName, Size)		= type select
		fToArea(FieldName, Rows, Cols)	= type textarea
		fToDate(FieldName, Size) 		= 3 selects type
		fToBox(FieldName, num)			= type Checkbox or Radiobutton
		*/
	echo $sform->fDisplayError("lname");
	echo $sform->fToField("lname",20);?><br><br>

	<?echo $sform->fVisualName("fname")?><br>

	<?echo $sform->fToField("fname",20)?><br><br>

	<?echo $sform->fVisualName("email")?><br>
	<?echo $sform->fToField("email",20)?><br><br>

	<?echo $sform->fVisualName("birth")?><br>
	<?echo $sform->fToDate("birth",1)?><br><br>

	<?echo $sform->fVisualName("message")?><br>
	<?echo $sform->fToArea("message",20,5,"")?><br><br>

	<?echo $sform->fVisualName("country")?><br>
	<?echo $sform->fToSelect("country",1)?><br><br>

	<?echo $sform->fVisualName("mlist")?><br>
	<?
	/* ********************************************
		display all items to Radio/Checkbox field*/
	for ($n=0; $n<=count($sform->fMaxOption("mlist"))-1; $n++) {
		echo $sform->fToBox("mlist",$n)."<br>".chr(10);
	}
	?><br><br>
		<input type="submit" name="send" value="send">
	</form>
	</body>
</html>