Location: PHPKode > scripts > Skunky Form > skunky-form/examples/examplemdb2.php
<?php
/**
 * Example usage of SkunkyForm Package with mdb2 connection using the method addfield
 *
 * @package SkunkyForm
 */

require_once 'MDB2.php';

$dsn = array(
    'phptype'  => 'mysql',
    'username' => 'root',
    'password' => 'root',
    'hostspec' => 'localhost',
    'database' => 'tp_dam',
);

$options = array(
    'debug'       => 2,
    'portability' => MDB2_PORTABILITY_ALL,
);

$mdb2 =& MDB2::connect($dsn, $options);

require_once('../Form.php');

?>
<!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
	$monForm = new Form();
	/*
		$monForm->addField("field name (same as the field's name in the database)" , array(
		"label"=>"name of the label", 
		"required"=>true if the field is obligatory to be mentionned false if not, 
		"rule"=>"name of the field's rule", 
		"type"=>"type of the field : textarea, radio, select, checkbox or input", 
		"errormsg" => "message you want to display if error"
		"options" => array(
			"use this array for radio, select and checkbox"
		)
	));
	*/
	$monForm->addField("last_name", array(
		"label"=>"Nom", 
		"required"=>true, 
		"rule"=>"validateName", 
		"type"=>"input", 
		"errormsg" => "Votre message n'est pas valide !"
	));
	$monForm->addField("first_name", array(
		"label"=>"Prénom", 
		"required"=>true, 
		"rule"=>"validateName", 
		"type"=>"input", 
		"errormsg" => "Votre prénom n'est pas valide !"
	));
	$monForm->addField("mail", array(
		"label"=>"Email",
		"required"=>true, 
		"rule"=>"validateMail", 
		"type"=>"input", 
		"errormsg" => "Votre adresse email n'est pas valide !"
	));
	$monForm->addField("message", array(
		"label"=>"Message", 
		"required"=>false, 
		"rule"=>"", 
		"type"=>"textarea", 
		"errormsg" => "Votre message n'est pas valide !"
	));
	
	$monForm->setActiveJs(true);
	
	if(!empty($_POST)) {
		$monForm->setFrom($_POST);
		if ($monForm->validate()) {
			$monForm->saveForm("mdb2", $mdb2, "post_list");
			$monForm->displayResult();
			/*
			try {
				$monForm->sendByMail("hide@address.com");
			} catch(Exception $e){
				echo $e->getMessage();
			}
			*/
		} else {
			$monForm->displayForm();
		}
	} else {
		$monForm->displayForm();
	}
	?>
</body>
</html>    
Return current item: Skunky Form