<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Monolith Development &#187; php</title>
	<atom:link href="http://monolithdev.us/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://monolithdev.us</link>
	<description>&#60;&#63; &#47;&#47; I build stuff. &#63;&#62;</description>
	<lastBuildDate>Mon, 23 Aug 2010 22:51:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Logging Emails Sent Through Wordpress</title>
		<link>http://monolithdev.us/logging-emails-sent-through-wordpress/</link>
		<comments>http://monolithdev.us/logging-emails-sent-through-wordpress/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 17:49:05 +0000</pubDate>
		<dc:creator>darren</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://monolithdev.us/?p=227</guid>
		<description><![CDATA[Ever have the need to log emails from a contact form inside of of wordpress? Here&#8217;s my solution.
The Problem
The client uses the Contact Form 7 wordpress plugin for events, registrations and subscriptions. Up until this point all the emails needed to be cut and pasted manually into a master list for marketing or other action [...]]]></description>
			<content:encoded><![CDATA[<p>Ever have the need to log emails from a contact form inside of of <a href="http://wordpress.org/" target="_blank">wordpress</a>? Here&#8217;s my solution.</p>
<h3 class="bold"><strong>The Problem</strong></h3>
<p>The client uses the <a href="http://wordpress.org/extend/plugins/contact-form-7/" target="_blank">Contact Form 7</a> wordpress plugin for events, registrations and subscriptions. Up until this point all the emails needed to be cut and pasted manually into a master list for marketing or other action items.</p>
<p>Specific actions are taken with each contact form. Some are simply added to a master email list while others are used to send content through snail mail. The need for more forms over the next few months will be increasing. These forms are very time sensitive so the solution must be dynamic enough to preclude more than a few hours in turnaround.</p>
<h3 class="bold"><strong>The Solution</strong></h3>
<p>If resources were unlimited (time and budget) this would be a great place to implement pre-built CRM (customer relations mangment) system. There are plenty of open source and commercial applications that would work well.</p>
<p>The biggest limiting resource here is time. The client knows how use wordpress and the current site is already well established with content. So we&#8217;ll hack it.</p>
<h3 class="bold"><strong>Logging Emails</strong></h3>
<p>Logging outgoing emails from any type of contact form is essential. This could be as simple as storing them in a database or even writing to a flat file. Logging emails will help you pick up security issues as well as troubleshooting.</p>
<p>The solution is pretty simple. Every email sent out through wordpress uses the <a href="http://codex.wordpress.org/Function_Reference/wp_mail" target="_blank"><strong>wp_mail()</strong></a> function, including forms through Contact 7. All we need to do is capture the $_POST variables when a call is made to wp_mail().</p>
<p>We can use the <a href="http://codex.wordpress.org/Function_Reference/add_action" target="_blank"><strong>add_action()</strong></a> hook from wordpress to accomplish this.</p>
<h3 class="bold"><strong>A simple example</strong></h3>
<p>We&#8217;ll insert our hook in the functions.php page for the theme. For this example I&#8217;ll use a theme called <em>custom</em>.</p>
<pre>wp-content/themes/custom/functions.php</pre>
<p>We&#8217;ll create a function to capture the posts. This function won&#8217;t really do anything but you&#8217;ll get the point. Then we&#8217;ll hook the function into wp_mail().</p>
<pre>function saveContact() {
    // all of our post variables are in the $contact array
    $contact = $_POST;

    // now would be a good time to clean and filter
    foreach( $contact as $key =&gt; $value ) {
        // trim it, escape ... it you know the drill
    }

    // insert into the database or save a flat file

}

// hook it
add_action( 'wp_mail', 'saveContact' );</pre>
<p>Now anytime wordpress sends an email it will call our saveContact() function. This is fine to just capture the data but we want to do something with it. Keep in mind Contact 7 adds in some of its own post variables so you may want to pop those off before processing the data.</p>
<p>If you want to echo anything back to test this turn off your javascript otherwise Contact 7 will send an ajax call behind the scenes.</p>
<h3 class="bold"><strong>An advanced example (go cURL yourself)</strong></h3>
<p>Wordpress is great but I want to use a MVC framework to handle all of the the different actions. I want to know what form was sent and use the information to populate various tables. I use Kohana but any of the popular frameworks can handle this in the same way. The benefit here is I can use the framework&#8217;s built in cleaning and database helpers. We&#8217;ll use cURL to send the post variables to our controller.</p>
<p>I&#8217;ll send the data to a controller in public_html/example. So the domain www.mydomain.com has a standard wordpress install but we have a <a href="http://kohanaphp.com/" target="_blank">kohana</a> controller living in www.mydomain.com/example. I&#8217;ll also send along the URI where the form originated. We&#8217;ll take care of all the data inside the framework. Clear as mud?</p>
<p>Wordpress by the way does not like putting this source code inside the post. You can check it out <a href="http://monolithdev.us/dev/demo/curl-yourself.phps" target="_blank">here</a>.</p>
<p>For security you can make sure the cURL posts are only sent from your domain.</p>
<p>With permalinks enabled you can differentiate between forms posted from something like www.mydomain.com/contact and www.mydomain.com/contact/subscribe.</p>
]]></content:encoded>
			<wfw:commentRss>http://monolithdev.us/logging-emails-sent-through-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kohana &#8211; My New Framework Of Choice</title>
		<link>http://monolithdev.us/kohana-my-new-framework-of-choice/</link>
		<comments>http://monolithdev.us/kohana-my-new-framework-of-choice/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 14:14:49 +0000</pubDate>
		<dc:creator>darren</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://monolithdev.us/?p=220</guid>
		<description><![CDATA[
I&#8217;ve been trying to come to a conclusion of what php framework to use on new projects. I finally took the plunge into Kohana and I&#8217;m loving it. Some of the other frameworks that made the short list. 

Zoop &#8211; I like the command line, smarty, and PEAR integration.
CodeIgniter &#8211; Great documentation, huge community and [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://monolithdev.us/wp-content/uploads/2010/02/kohana-300x116.png" alt="kohana" title="kohana" width="300" height="116" class="aligncenter size-medium wp-image-219" /></p>
<p>I&#8217;ve been trying to come to a conclusion of what php framework to use on new projects. I finally took the plunge into <a href="http://kohanaphp.com/" target="_blank">Kohana</a> and I&#8217;m loving it. Some of the other frameworks that made the short list. </p>
<ul>
<li><a href="http://zoopframework.com/" target="_blank">Zoop</a> &#8211; I like the command line, smarty, and PEAR integration.</li>
<li><a href="http://codeignitor.com/" target="_blank">CodeIgniter</a> &#8211; Great documentation, huge community and heavily used.</li>
<li><a href="http://www.tinymvc.com/" target="_blank">TinyMVC</a> &#8211; Stripped down version of CodeIgniter. Easy integration into smarty.</li>
<li><a href="http://framework.zend.com/" target="_blank">Zend</a> &#8211; All the cool kids are doing it.</li>
</ul>
<p>Like most developers I fought the extreme urge to do everything myself and reinvent the wheel. Although I could of expedited that decision. In the end choosing a well documented and community driven framework makes any application more valuable. It helps when other developers get involved and don&#8217;t have to guess what it is your doing. It sets the standard and hundreds or thousands of developers have contributed to that standard. In short it reduces the <strong>&#8220;WTF?&#8221;</strong> moments.</p>
<p>If I need a hand on a project or turn it over to someone else the next developer can pick up where I left off. Some of the features that sealed the deal for me. </p>
<ul>
<li>Security &#8211; filters XSS by default. No configuration needed.</li>
<li>Large module/plugin library</li>
<li>Ajax integration and seperation is easy to work with.
<li>
<li>Strict OOP</li>
</ul>
<p>Development is very fast with Kohana. The more I dig into the more I&#8217;m enjoying it. </p>
]]></content:encoded>
			<wfw:commentRss>http://monolithdev.us/kohana-my-new-framework-of-choice/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Form Usability: Returning Users Invalid Input</title>
		<link>http://monolithdev.us/form-usablity-returning-users-invalid-input/</link>
		<comments>http://monolithdev.us/form-usablity-returning-users-invalid-input/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 21:06:06 +0000</pubDate>
		<dc:creator>darren</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://monolithdev.us/?p=201</guid>
		<description><![CDATA[I spend allot of time creating forms. Lots and lots of forms. Most of the development time is spent to validating and cleaning the data of these forms. Normally I do light validation client side with jQuery and then strong validation on the server side with php. Only after the data passes do I actually [...]]]></description>
			<content:encoded><![CDATA[<p>I spend allot of time creating forms. Lots and lots of forms. Most of the development time is spent to validating and cleaning the data of these forms. Normally I do light validation client side with jQuery and then strong validation on the server side with php. Only after the data passes do I actually do something with it, which usually includes cleaning or filtering first. </p>
<h3>The Problem</h3>
<p>If the submitted form doesn&#8217;t pass validation I want to return the data so the user doesn&#8217;t have to re-enter all the information. I don&#8217;t want to rely on javascript, although I will add it for user convenience as a final step. I also don&#8217;t want the form re-submitted if the user refreshes. </p>
<h3>The Solution</h3>
<p>There are quite a few ways to solve these problems. My standard approach is to post the form to a processing page and store the POST variables in a session. If the data fails the validation I redirect to the original form, pull the submitted data out of the session variables and re-populate the form with an error message. </p>
<p>Pretty straight forward for small contact forms. Once you get to a gigantic form that makes your eyes bleed this becomes cumbersome. <em>On a side not I try to push my clients to the smallest possible forms they can get away with.</em>. </p>
<p>I use a <em>postToSession</em> class to make this go a little quicker. </p>
<h3>Example Usage</h3>
<p>I&#8217;ll use three files for my example. Comments are in the source files. </p>
<ul>
<li><a href="http://monolithdev.us/dev/demo/post-to-session/index.phps" target="_blank">index.php</a></li>
<li><a href="http://monolithdev.us/dev/demo/post-to-session/process.phps" target="_blank">process.php</a></li>
<li><a href="http://monolithdev.us/dev/demo/post-to-session/postToSession.phps" target="_blank">postToSession.php</a></li>
</ul>
<p>You can see a working demo of these files in action <a href="http://monolithdev.us/dev/demo/post-to-session/index.php" target="_blank">here</a>. </p>
<p>Basically by using this class I can automatically serialize the form value and stuff it into a session variable. Once I unpack it, it cleans itself up. </p>
<p>Lets start with process.php. The form has been submitted. We  instantiate the postToSession class and pass a parameter of <em>_formValues</em> to the constructor. This is the name of the session variable we&#8217;ll use. </p>
<pre>
$session = new postToSession( '_formValues' );
</pre>
<p>Next we&#8217;ll serialize the post values and store them in the session variable. </p>
<pre>
$session->serializePost();
</pre>
<p>Now that you&#8217;ve saved the posted values you can work validation to your hearts content and set any error messages according. If no error messages are sent the data is ready to go. In this example I simply set a status message and pass them back to the original page. If an error message is set I&#8217;ll send them back with <em>failed</em> in the query string.</p>
<p>Either way they are going back to the index page. On index.php I&#8217;ll look for the failed variable in the query string. If its set I can pull all the values back out and re-populate the form. I&#8217;ll put the values in a local array called $formValues.</p>
<pre>
$formValues = $session->unserializePost();
</pre>
<p>Now I&#8217;ll assign the form values to print out to the user. If it $_GET['failed'] isn&#8217;t set I know we either passed form validation or its a fresh start. I&#8217;ll also check to see if there is a status message set in the $_SESSION variables. If it is I&#8217;ll assign it to a local variable for display and clear it. </p>
<h3>The End</h3>
<p>This is just one of those little tricks I wish someone had shown me when I started. By using a separate page to process and redirecting after processing we can keep the user from submitting multiple times by pressing the refresh button. You could just as easily use the query string to repopulate the form but it looks horrible. I also use this method because many times the form is pre-populated with information like the users profile or other account information. I can use the same template for adding new records as well as editing existing records. </p>
]]></content:encoded>
			<wfw:commentRss>http://monolithdev.us/form-usablity-returning-users-invalid-input/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Developer Dilemmas</title>
		<link>http://monolithdev.us/developer-dilemmas/</link>
		<comments>http://monolithdev.us/developer-dilemmas/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 20:14:45 +0000</pubDate>
		<dc:creator>darren</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://monolithdev.us/?p=153</guid>
		<description><![CDATA[
This was a little over an hour worth of my life that I&#8217;ll never get back. 
During development I run with errors set to E_ALL and turn off error reporting for the live site. Today I thought I would see how E_STRICT would pan out on the framework I use. I knew I would get [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://monolithdev.us/wp-content/uploads/2009/07/php-logo.png" alt="php-logo" title="php-logo" width="180" height="95" class="aligncenter size-full wp-image-156" /></p>
<p>This was a little over an hour worth of my life that I&#8217;ll never get back. </p>
<p>During development I run with errors set to E_ALL and turn off error reporting for the live site. Today I thought I would see how E_STRICT would pan out on the framework I use. I knew I would get some new errors so I was already bracing for impact. In PHP6 E_STRICT is to take the place of E_ALL so I figured a Sunday afternoon would be a good time to see what I had in store for me for PHP6.</p>
<p>I try to take advantage of any pear packages I can get a hold of. Pear&#8217;s goal is to offer backward compatibility so between some of my own code and pear there was allot of notices. Most of them coming from pear&#8217;s use of is_a(). </p>
<p>As I looked deeper into into the topic I started to think it was time to move away from PEAR and rethink my framework. Wow, that&#8217;s allot of time and allot of work. There are allot of good changes for PHP6. Most of them are reducing the ability to create poorly written scripts. </p>
<p>An hour later I decided I&#8217;ll look at this again after PHP6 is stable (could be a while). I don&#8217;t why I do this stuff to myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://monolithdev.us/developer-dilemmas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
