Location: PHPKode > scripts > Skunky Form > skunky-form/examples/exampledataobject.php
<?php
/**
 * Example usage of SkunkyForm Package with dataobject Connection passing an array in the constructor
 *
 * @package SkunkyForm
 */
 
require_once 'PEAR.php';
define("DB_DATAOBJECT_NO_OVERLOAD",true);//This is needed for some buggy versions of PHP4
require_once "DB/DataObject.php";
require_once "Structures/DataGrid.php";
require_once('../Form.php');

$dataobjectOptions =& PEAR::getStaticProperty("DB_DataObject","options");
$dataobjectOptions["database"] = "mysql://root:hide@address.com/tp_dam";
$dataobjectOptions["proxy"] = "full";

class DataObject_Post_list extends DB_DataObject
{
public $__table="post_list";
public $id;
public $last_name;
public $first_name;
public $mail;
public $message;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" >
<head>
	<title>Premier TP</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<!--##### CSS #####-->
	<link rel="stylesheet" media="screen" type="text/css" href="../css/structure.css" />
	<link rel="stylesheet" media="screen" type="text/css" href="../css/form.css" />
	<link rel="stylesheet" media="screen" type="text/css" href="../css/result.css" />
</head>
<body id="public">
<?php
$dataobject =& new DataObject_Post_list();

	$monTab = array(
		"last_name" => array(
			"label" => "Nom",
			"required" => true, 
			"rule" => "validateName",
			"type" => "input",
			"errormsg" => "Votre nom n'est pas valide !",
			"options" => array()	
		),
		"first_name" => array(
			"label" => "Prénom",
			"required" => true, 
			"rule" => "validateName",
			"type" => "input",
			"errormsg" => "Votre prénom n'est pas valide !",
			"options" => array()
		),
		"mail" => array(
			"label" => "Email",
			"required" => true, 
			"rule" => "validateMail",
			"type" => "input",
			"errormsg" => "Votre adresse email n'est pas valide !",
			"options" => array()
		),
		"message" => array(
			"label" => "Message",
			"required" => false,
			"rule" => "",
			"type" => "textarea",
			"errormsg" => "Votre message n'est pas valide !",
			"options" => array()
		)	
	);
	$monForm = new Form($monTab);
	
	$monForm->setActiveJs(true);
	
	if(!empty($_POST)) {
		$monForm->setFrom($_POST);
		if ($monForm->validate()) {
			$monForm->saveForm("DataObject", $dataobject);
			$monForm->displayResult();
		} else {
			$monForm->displayForm();
		}
	} else {
		$monForm->displayForm();
	}
?>
</body>
</html>
Return current item: Skunky Form