PHP-Tutorial -> competition/input.php
<?php
define( "TMPL_PATH", "../templates" );
define( "TMPL_FILE", "userform.tmpl" );
define( "MAIL_ADDR", "<E-MAIL>" );
define( "MAIL_SUBJ", "Competition" );
/* Home: http://pear.php.net/package/HTML_Template_IT */
require_once "HTML/Template/IT.php";
// Init
$template = new HTML_Template_IT( TMPL_PATH );
$template->loadTemplatefile( TMPL_FILE, true, true );
$name = "";
$email = "";
$bear = "";
$status = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") { // process input
if ( !($_POST["name"] && $_POST["email"] && $_POST["bear"]) ) { // error
if ( $_POST["name"] ) $name .= $_POST["name"];
else $status .= "Your name is missing.<br>";
if ( $_POST["email"] ) $email .= $_POST["email"];
else $status .= "Your e-mail address is missing.<br>";
if ( $_POST["bear"] ) $bear .= $_POST["bear"];
else $status .= "Which name do you suggest for our mascot?<br>";
$status .= "Please fill in the required information!";
} else { // no error
$formulardaten = "Name: " . $_POST["name"] . "\nE-Mail: " . $_POST["email"] .
"\nSuggestion: " . $_POST["bear"];
if ( mail (MAIL_ADDR, MAIL_SUBJ, $formulardaten) ) {
$name = "";
$email = "";
$bear = "";
$status .= "Your suggestion has been received. Thank you!";
} else {
$status .= "Sorry, an error occured during message delivery!";
}
}
} // else show empty formular
// Data processing
$template->
setVariable( "name", $name );
$template->setVariable( "email", $email );
$template->setVariable( "bear", $bear );
$template->setVariable( "status", $status );
$template->parseCurrentBlock();
// Create HTML output
header('Content-Type: text/html; charset=utf-8');
$template->show();
?>