Screencast: Building a PHP contact form with the Zoop Framework

And here are the code snippets I used in this screencast:

pageDefault

	/**
	 * pageDefault
	 *
	 * @param mixed $inPath
	 * @access public
	 * @return void
	 */
	function pageDefault($inPath)
	{
	// 	You may usually want the following line, but for our demo we don't
	// 	$this->zoneRedirect("login");
 
 		global $sGlobals;
 		global $gui;
 
 		//this is for gets.  It displays the page
 		$gui->display("contact-form.tpl");
	}

postDefault

	/**
	 * postDefault
	 *
	 * @param mixed $inPath
	 * @access public
	 * @return void
	 */
	function postDefault($inPath)
	{
		global $sGlobals, $gui;
		//this is for posts, it handles when forms get submitted.
 
		$post = getPost();
 
		$from = $post['address'];
		$to = 'justin@mailinator.com';
		$cc = null;
		$subject = $post['subject'];
		$body = $post['message'];
 
		$msg = new message();
		$msg->sendTextEmail($from, $to, $cc, $subject, $body);
 
		$gui->assign('message', 'Thanks for contacting us!');
		$gui->display('message.tpl');
	}

Note: It's not a good practice to actually display things in the post handlers. As a general rule, you should do your emailing and form handling in the post handler, then redirect to a page function to display feedback. Something like this:

	/**
	 * postDefault
	 *
	 * @param mixed $inPath
	 * @access public
	 * @return void
	 */
	function postDefault($inPath)
	{
		global $sGlobals;
		//this is for posts, it handles when forms get submitted.
 
		$post = getPost();
 
		$from = $post['address'];
		$to = 'justin@mailinator.com';
		$cc = null;
		$subject = $post['subject'];
		$body = $post['message'];
 
		$msg = new message();
		$msg->sendTextEmail($from, $to, $cc, $subject, $body);
 
		zoneRedirect('thanks');
	}
 
	/**
	 * pageThanks
	 *
	 * @param mixed $inPath
	 * @access public
	 * @return void
	 */
	function pageThanks($inPath)
	{
		global $sGlobals, $gui;
		$gui->assign('message', 'Thanks for contacting us!');
		$gui->display('message.tpl');
	}

Contact form template

{include file="head.tpl"}
<body>
 
<h1>Contact Me!</h1>
 
<p>Fill out the form below to contact me.</p>
 
<form method="POST">
 
	<div>
		<label for="name">Name:</label>
		<input name="name" id="name" type="text" />
	</div>
 
	<div>
		<label for="address">Email address:</label>
		<input name="address" id="address" type="text" />
	</div>
 
	<div>
		<label for="subject">Subject:</label>
		<input name="subject" id="subject" type="text" />
	</div>
 
	<div>
		<label for="message">Message:</label>
		<textarea name="message" id="message"></textarea>
	</div>
 
	<input type="submit" name="submit" value="Send Message" />
</form>
 
</body></html>