<?php
/**
* Example usage of SkunkyForm Package with db connection using the method addfield with all the differents possible fields you can use
*
* @package SkunkyForm
*/
require_once 'DB.php';
$dsn = array(
'phptype' => 'mysql',
'username' => 'root',
'password' => 'root',
'hostspec' => 'localhost',
'database' => 'tp_dam',
);
$options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL,
);
$db =& DB::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 required, 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() // for radio, select and checkbox (with key as field value and array value as display value)
));
*/
$monForm->addField("gender", array(
"label"=>"Gender",
"required"=>true,
"rule"=>"",
"type"=>"radio",
"errormsg" => "Your gender is required !",
"options" => array(
"Mrs" => "Mrs",
"Mr" => "Mr"
)
));
$monForm->addField("last_name", array(
"label"=>"Last Name",
"required"=>true,
"rule"=>"validateName",
"type"=>"input",
"errormsg" => "Last Name is not valid !"
));
$monForm->addField("first_name", array(
"label"=>"First Name",
"required"=>true,
"rule"=>"validateName",
"type"=>"input",
"errormsg" => "First Name is not valid !"
));
$arr_years = array();
for ($i=1900; $i<date("Y"); $i++) {
$arr_years[$i] = $i;
}
$monForm->addField("birth_year", array(
"label"=>"Birth Year",
"required"=>true,
"rule"=>"",
"type"=>"select",
"errormsg" => "Your birth year is required !",
"options" => $arr_years
));
$monForm->addField("mail", array(
"label"=>"Email",
"required"=>true,
"rule"=>"validateMail",
"type"=>"input",
"errormsg" => "Your email address is not valid !"
));
$monForm->addField("message", array(
"label"=>"Message",
"required"=>false,
"rule"=>"",
"type"=>"textarea",
"errormsg" => "Your message is not valid !"
));
$monForm->addField("newsletter", array(
"label"=>"Newsletter Registration",
"required"=>false,
"rule"=>"",
"type"=>"checkbox",
"errormsg" => "You have to check this box !",
"options" => array(
"yes" => "Yes",
)
));
$monForm->setActiveJs(true);
if(!empty($_POST)) {
$monForm->setFrom($_POST);
if ($monForm->validate()) {
$monForm->saveForm("db", $db, "post_list");
$monForm->displayResult();
/*
try {
$monForm->sendByMail("hide@address.com");
} catch(Exception $e){
echo $e->getMessage();
}
*/
} else {
$monForm->displayForm();
}
} else {
$monForm->displayForm();
}
?>
</body>
</html>