<?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>The Tutorial Blog &#187; howto</title>
	<atom:link href="http://www.thetutorialblog.com/tag/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.thetutorialblog.com</link>
	<description></description>
	<lastBuildDate>Wed, 07 Jul 2010 23:30:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<image>
<link>http://www.thetutorialblog.com</link>
<url>http://www.thetutorialblog.com/wp-content/plugins/maxblogpress-favicon/icons/favicon-28.ico</url>
<title>The Tutorial Blog</title>
</image>
		<item>
		<title>Adding security to CodeIgniter forms with a custom library class</title>
		<link>http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/</link>
		<comments>http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 14:03:48 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[CI]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=159</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	The class that we are going to create within CI will simply add a math question that the user will have to enter correctly to continue. This is useful to stop bots from mass submitting information to your forms. The class we are going to write is only very short and simple, but it will [...]


Related posts:<ol><li><a href='http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery-part-2/' rel='bookmark' title='Permanent Link: Build a Twitter-like site with CodeIgniter and jQuery Part 2'>Build a Twitter-like site with CodeIgniter and jQuery Part 2</a> <small>Don't forget to check out part 1 if you have...</small></li>
<li><a href='http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Twitter-like pagination using CodeIgniter and jQuery'>Twitter-like pagination using CodeIgniter and jQuery</a> <small>If you use Twitter you'll notice that there is a...</small></li>
<li><a href='http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Build a Twitter-like site with CodeIgniter and jQuery'>Build a Twitter-like site with CodeIgniter and jQuery</a> <small>This tutorial will be the first of a five part...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fadding-security-to-codeigniter-forms-with-a-custom-library-class%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fadding-security-to-codeigniter-forms-with-a-custom-library-class%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Adding security to CodeIgniter forms with a custom library class" alt=" Adding security to CodeIgniter forms with a custom library class" /><br />
			</a>
		</div>
<p>The class that we are going to create within CI will simply add a math question that the user will have to enter correctly to continue. This is useful to stop bots from mass submitting information to your forms.</p>
<p>The class we are going to write is only very short and simple, but it will give you an idea of how to create classes for your own projects.</p>
<h2>Creating the new class</h2>
<p>First of all we need to create the file for the class, navigate to libraries then create a file called math_question.php.</p>
<p>All we are going to do within this class is generate two random numbers that will be added together.<br />
<span id="more-159"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> math_question <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> questionOne<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// generate a random number between 0 - 10</span>
		<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$num</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> questionTwo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$num</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is all we will be doing for the code within the class.</p>
<h2>Using the class within a form</h2>
<p>To use this class in our controller we load it like so:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We will also be using form validation and sessions to check if the user has entered the correct answer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>We need to set questionOne and questionTwo in variables so we can assign them to a temporary flash session and because they will be passed into the view.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$questionOne</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">math_question</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionOne</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$questionTwo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">math_question</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionTwo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionOne'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$questionOne</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionTwo'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$questionTwo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;What is <span style="color: #006699; font-weight: bold;">{$questionOne}</span> + <span style="color: #006699; font-weight: bold;">{$questionTwo}</span>?&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>To check that the answer that is wrote in is correct we use the callback method in our form validation to call a function that we create that will check the users input against the flash data.</p>
<p>This is how we set our form validation:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Math Question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'callback_math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Then we check if the validation has been executed:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact/form'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we need to create our function that is called upon validation of the form:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> math_question<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$user_answer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$questionOne</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionOne'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$questionTwo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionTwo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$correct_answer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$questionOne</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$questionTwo</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_answer</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$correct_answer</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Your answer to the math question was incorrect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will check if what the user has input is correct against a temporary flash session.</p>
<p>Here is all of the controller code in full:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> Contact <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'form_validation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'session'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$questionOne</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">math_question</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionOne</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$questionTwo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">math_question</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">questionTwo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionOne'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$questionOne</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionTwo'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$questionTwo</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;What is <span style="color: #006699; font-weight: bold;">{$questionOne}</span> + <span style="color: #006699; font-weight: bold;">{$questionTwo}</span>?&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Math Question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'callback_math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact/form'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> math_question<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$user_answer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$questionOne</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionOne'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$questionTwo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashdata</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'questionTwo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$correct_answer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$questionOne</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$questionTwo</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user_answer</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$correct_answer</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_message</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'math_question'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Your answer to the math question was incorrect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Create the view</h2>
<p>The last thing we need to do is create the view. Goto views and create a folder called contact, within that folder create a file called form.php.</p>
<p>Here is the code for form.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> validation_errors<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> form_open<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'contact'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
Name: &lt;input type=&quot;text&quot; name=&quot;name&quot; /&gt; &lt;br /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$math_question</span><span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;br /&gt;
Answer: &lt;input type=&quot;text&quot; name=&quot;math_question&quot; /&gt; &lt;br /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Send!&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">echo</span> form_close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>On the first line we output the validation errors if there is any, on the second line we use the form helper to open the form tags and likewise for the bottom line where we close the form. $math_question is the variable that is passed in from the controller.</p>
<h2>Post your thoughts</h2>
<p>Let us know what you think of the tutorial and share your thoughts and contributions below in the comments.</p>


<p>Related posts:<ol><li><a href='http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery-part-2/' rel='bookmark' title='Permanent Link: Build a Twitter-like site with CodeIgniter and jQuery Part 2'>Build a Twitter-like site with CodeIgniter and jQuery Part 2</a> <small>Don't forget to check out part 1 if you have...</small></li>
<li><a href='http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Twitter-like pagination using CodeIgniter and jQuery'>Twitter-like pagination using CodeIgniter and jQuery</a> <small>If you use Twitter you'll notice that there is a...</small></li>
<li><a href='http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Build a Twitter-like site with CodeIgniter and jQuery'>Build a Twitter-like site with CodeIgniter and jQuery</a> <small>This tutorial will be the first of a five part...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Form Validation</title>
		<link>http://www.thetutorialblog.com/video-tutorials/jquery-form-validation/</link>
		<comments>http://www.thetutorialblog.com/video-tutorials/jquery-form-validation/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 20:38:47 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[Video Tutorials]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=82</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	Create a form that requires the user to enter both a username and password. If the username field or password field is left blank then a message will be displayed. Related posts:Build a Twitter-like site with CodeIgniter and jQuery Part 2 Don't forget to check out part 1 if you have... jQuery Dropdown Suggestions For [...]


Related posts:<ol><li><a href='http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery-part-2/' rel='bookmark' title='Permanent Link: Build a Twitter-like site with CodeIgniter and jQuery Part 2'>Build a Twitter-like site with CodeIgniter and jQuery Part 2</a> <small>Don't forget to check out part 1 if you have...</small></li>
<li><a href='http://www.thetutorialblog.com/jquery/jquery-dropdown-suggestions/' rel='bookmark' title='Permanent Link: jQuery Dropdown Suggestions'>jQuery Dropdown Suggestions</a> <small>For this tutorial we are going to create a drop...</small></li>
<li><a href='http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/' rel='bookmark' title='Permanent Link: Adding security to CodeIgniter forms with a custom library class'>Adding security to CodeIgniter forms with a custom library class</a> <small>The class that we are going to create within CI...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fvideo-tutorials%2Fjquery-form-validation%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fvideo-tutorials%2Fjquery-form-validation%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="jQuery Form Validation" alt=" jQuery Form Validation" /><br />
			</a>
		</div>
<p>Create a form that requires the user to enter both a username and password. If the username field or password field is left blank then a message will be displayed.</p>
<p><object type="application/x-shockwave-flash" width="512" height="399" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://blip.tv/scripts/flash/showplayer.swf" /><param name="flashvars" value="init=http://blip.tv/play/AYGN4GwA" /><embed src="http://blip.tv/play/AYGN4GwA" type="application/x-shockwave-flash" width="512" height="399" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>


<p>Related posts:<ol><li><a href='http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery-part-2/' rel='bookmark' title='Permanent Link: Build a Twitter-like site with CodeIgniter and jQuery Part 2'>Build a Twitter-like site with CodeIgniter and jQuery Part 2</a> <small>Don't forget to check out part 1 if you have...</small></li>
<li><a href='http://www.thetutorialblog.com/jquery/jquery-dropdown-suggestions/' rel='bookmark' title='Permanent Link: jQuery Dropdown Suggestions'>jQuery Dropdown Suggestions</a> <small>For this tutorial we are going to create a drop...</small></li>
<li><a href='http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/' rel='bookmark' title='Permanent Link: Adding security to CodeIgniter forms with a custom library class'>Adding security to CodeIgniter forms with a custom library class</a> <small>The class that we are going to create within CI...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/video-tutorials/jquery-form-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery #1</title>
		<link>http://www.thetutorialblog.com/video-tutorials/jquery-1/</link>
		<comments>http://www.thetutorialblog.com/video-tutorials/jquery-1/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 22:45:40 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[Video Tutorials]]></category>
		<category><![CDATA[animate]]></category>
		<category><![CDATA[blip]]></category>
		<category><![CDATA[blip.tv]]></category>
		<category><![CDATA[effect]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=73</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	Learn how to use the animate function within the jQuery library to create an effect similar to the table of contents for the table of contents on codeigniter.com. Blip.tv Link Click to play Related posts:Deep Linking with jQuery You can view a demo and download the resources for... Build a Twitter-like site with CodeIgniter and [...]


Related posts:<ol><li><a href='http://www.thetutorialblog.com/jquery/deep-linking-with-jquery/' rel='bookmark' title='Permanent Link: Deep Linking with jQuery'>Deep Linking with jQuery</a> <small>You can view a demo and download the resources for...</small></li>
<li><a href='http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Build a Twitter-like site with CodeIgniter and jQuery'>Build a Twitter-like site with CodeIgniter and jQuery</a> <small>This tutorial will be the first of a five part...</small></li>
<li><a href='http://www.thetutorialblog.com/jquery/10-awesome-jquery-tutorials-you-should-check-out/' rel='bookmark' title='Permanent Link: 10 Awesome jQuery Tutorials You Should Check Out'>10 Awesome jQuery Tutorials You Should Check Out</a> <small>jQuery is a great tool that everyone in web development...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fvideo-tutorials%2Fjquery-1%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fvideo-tutorials%2Fjquery-1%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="jQuery #1" alt=" jQuery #1" /><br />
			</a>
		</div>
<p>Learn how to use the animate function within the jQuery library to create an effect similar to the table of contents for the table of contents on codeigniter.com. </p>
<p><a href="http://thetutorialblog.blip.tv/file/2296444/">Blip.tv Link</a></p>
<p><span id="more-73"></span></p>
<p><center>															<script type="text/javascript" src="http://blip.tv/scripts/pokkariPlayer.js?ver=2008010901"></script>					<script type="text/javascript" src="http://blip.tv/syndication/write_player?skin=js&#038;posts_id=2312660&#038;source=3&#038;autoplay=true&#038;file_type=flv&#038;player_width=1024&#038;player_height=768"></script>
<div id="blip_movie_content_2312660">					<a rel="enclosure" href="http://blip.tv/file/get/Thetutorialblog-jQuery1834.flv" onclick="play_blip_movie_2312660(); return false;"><img title="Click to play" alt="Video thumbnail. Click to play" width="512" height="384" src="http://blip.tv/file/get/Thetutorialblog-jQuery1834.flv.jpg" border="0" title="Click to play" /></a>					<br />					<a rel="enclosure" href="http://blip.tv/file/get/Thetutorialblog-jQuery1834.flv" onclick="play_blip_movie_2312660(); return false;">Click to play</a>					</div>
<p>										</center></p>


<p>Related posts:<ol><li><a href='http://www.thetutorialblog.com/jquery/deep-linking-with-jquery/' rel='bookmark' title='Permanent Link: Deep Linking with jQuery'>Deep Linking with jQuery</a> <small>You can view a demo and download the resources for...</small></li>
<li><a href='http://www.thetutorialblog.com/php/build-a-twitter-like-site-with-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Build a Twitter-like site with CodeIgniter and jQuery'>Build a Twitter-like site with CodeIgniter and jQuery</a> <small>This tutorial will be the first of a five part...</small></li>
<li><a href='http://www.thetutorialblog.com/jquery/10-awesome-jquery-tutorials-you-should-check-out/' rel='bookmark' title='Permanent Link: 10 Awesome jQuery Tutorials You Should Check Out'>10 Awesome jQuery Tutorials You Should Check Out</a> <small>jQuery is a great tool that everyone in web development...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/video-tutorials/jquery-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://blip.tv/file/get/Thetutorialblog-jQuery1652.mov" length="34276983" type="video/quicktime" />
<enclosure url="http://blip.tv/file/get/Thetutorialblog-jQuery1834.flv" length="32154787" type="video/x-flv" />
		</item>
		<item>
		<title>Creating a WordPress plugin</title>
		<link>http://www.thetutorialblog.com/php/creating-a-wordpress-plugin/</link>
		<comments>http://www.thetutorialblog.com/php/creating-a-wordpress-plugin/#comments</comments>
		<pubDate>Fri, 21 Nov 2008 17:10:34 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Text Tutorials]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[makeuseof]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wp]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=38</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	The plugin that I'm going to show you how to create within this post is a plugin that I created for MakeUseOf. Creating plugins for WP is relatively easy and uses actions to call functions that are included in pages within the main WP files. To learn more about creating plugins for WP go here. [...]


Related posts:<ol><li><a href='http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Twitter-like pagination using CodeIgniter and jQuery'>Twitter-like pagination using CodeIgniter and jQuery</a> <small>If you use Twitter you'll notice that there is a...</small></li>
<li><a href='http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/' rel='bookmark' title='Permanent Link: Adding security to CodeIgniter forms with a custom library class'>Adding security to CodeIgniter forms with a custom library class</a> <small>The class that we are going to create within CI...</small></li>
<li><a href='http://www.thetutorialblog.com/cocoa-objective-c/creating-a-basic-ipad-application/' rel='bookmark' title='Permanent Link: Creating a basic iPad application'>Creating a basic iPad application</a> <small>Because of the recent announcement of the iPad more people...</small></li>
</ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
		<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fcreating-a-wordpress-plugin%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphp%2Fcreating-a-wordpress-plugin%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Creating a Wordpress plugin" alt=" Creating a Wordpress plugin" /><br />
			</a>
		</div>
<p>The plugin that I'm going to show you how to create within this post is a plugin that I created for <a href="http://www.makeuseof.com" target="_blank">MakeUseOf</a>.</p>
<p>Creating plugins for WP is relatively easy and uses actions to call functions that are included in pages within the main WP files. To learn more about creating plugins for WP go <a href="http://codex.wordpress.org/Main_Page" target="_blank">here</a>.</p>
<p>Ok so lets get started with creating the plugin.</p>
<p>When creating a plugin for WP make sure that you include your own unique word or acronym to your functions so that they don't conflict with any other plugins that may be installed.</p>
<p>Because I created this for MakeUseOf the acronym I use is MUO and then AF because I named the plugin author footer so every function within this plugin begins with MUO_AF.<br />
<span id="more-38"></span><br />
So to start our plugin we add this<br />
<div id="code_div">&lt;?php<br />
/*<br />
Plugin Name: MUO Author Footer<br />
Description: Authors type in the footer that will be attached to the end of their articles with modifications<br />
Author: Wez<br />
Version: 1.0<br />
*/<br />
</div></p>
<p>Here is where we add the name of our plugin, a description, your name and the version number of your plugin.</p>
<p>The next bit of code that we add is the <em>register_activation_hook</em> and <em>register_deactivation_hook</em> so that when the plugin is activated and deactivated the code within functions that we will create in our next step will be executed.<br />
<div id="code_div">register_activation_hook(__FILE__, 'MUO_AF_activate');<br />
register_deactivation_hook(__FILE__, 'MUO_AF_deactivate');</div></p>
<p>We're now going to create two functions called MUO_AF_activate and MUO_AF_deactivate so that the register hooks work correctly.<br />
<div id="code_div">function MUO_AF_activate() {<br />
	$query = mysql_query("CREATE TABLE `muo_author_footer` (<br />
	  `author_id` int(11) NOT NULL,<br />
	  `author_name` varchar(50) NOT NULL,<br />
	  `author_signature` text NOT NULL,<br />
	  PRIMARY KEY  (`author_id`)<br />
	) ENGINE=MyISAM DEFAULT CHARSET=latin1;");<br />
}</p>
<p>function MUO_AF_deactivate(){<br />
	$query = mysql_query("DROP TABLE `muo_author_footer`");<br />
}</div><br />
What this code does is when the plugin is activated it will create a table within the MySQL database that the plugin will use to store and retrieve information. When the plugin is deactivated it will delete the table that was created in the database.</p>
<p>In the next step we will write code that will be called and displayed within the Your Profile page in the admin-cp.<br />
<div id="code_div">function MUO_AF_profile() {<br />
	global $userdata;<br />
	get_currentuserinfo();<br />
	$query = mysql_query("SELECT * FROM muo_author_footer WHERE author_id='$userdata->ID'");<br />
	$row = mysql_fetch_array($query);<br />
	$author_signature = $row['author_signature'];<br />
	echo '&lt;table class="form-table"><br />
	&lt;tr>&lt;th>Author Post Signature</th>
<p>	&lt;td>&lt;p><br />
	&lt;textarea name="MUO_Author_Sig" cols="30" rows="5">'.$author_signature.'&lt;/textarea><br />
	&lt;/p><br />
	&lt;h2>Preview:&lt;/h2>&lt;p>&lt;em>';<br />
	echo $author_signature;<br />
	echo '&lt;/em>&lt;/p><br />
	&lt;/td>&lt;/tr><br />
	&lt;/table>';<br />
}</div></p>
<p>When the Update Profile button is clicked the information from the previous bit of code will be retrieved in the next bit of code and the database will be updated.<br />
<div id="code_div">function MUO_AF_edit(){<br />
	global $userdata, $current_user;<br />
	get_currentuserinfo();</p>
<p>	$MUO_Author_Sig = $_POST['MUO_Author_Sig'];</p>
<p>	$query = mysql_query("SELECT * FROM muo_author_footer WHERE author_id='$userdata->ID'");</p>
<p>	if( mysql_num_rows($query) > 0 ) {<br />
		$query = mysql_query("UPDATE muo_author_footer SET author_signature='$MUO_Author_Sig' WHERE author_id='$userdata->ID'");<br />
	} else {<br />
		$query = mysql_query("INSERT INTO muo_author_footer VALUES ('$userdata->ID','$userdata->user_login','$MUO_Author_Sig')");<br />
	}</p>
<p>}</div></p>
<p>The code we will write now is the code that will grab the contents of the post and then attach the authors signature to the end of that post.<br />
<div id="code_div">function MUO_AF_publish_post( $content ) {<br />
	global $wpdb;<br />
	$num = 0;<br />
	if (get_the_ID() > $num) {<br />
		$the_author_id = get_the_author_id();<br />
		$author_query = mysql_query("SELECT * FROM muo_author_footer WHERE author_id='". $the_author_id ."'");<br />
		$author_row = mysql_fetch_array($author_query);<br />
		$author_signature = $author_row['author_signature'];</p>
<p>		$content .= '&lt;style><br />
					.muo_af_style { background-color: #B4D0E1; border: 2px solid #4275B8; }<br />
					&lt;/style>';</p>
<p>		if(strstr($author_signature, 'by') == false) :</p>
<p>		$content .= '&lt;p class="muo_af_style">&lt;em>(By) '.$author_signature.'&lt;/em>&lt;/p>';</p>
<p>		else :</p>
<p>		$content .= '&lt;p class="muo_af_style">&lt;em>'.$author_signature.'&lt;/em>&lt;/p>';</p>
<p>		endif;</p>
<p>		return $content;<br />
	}<br />
	else {<br />
		return $content;<br />
	}<br />
}</div></p>
<p>We will now add the functions to actions, this is the most important part of the code because without this none of the functions would be called and nothing would happen.<br />
<div id="code_div">add_action('show_user_profile', 'MUO_AF_profile');<br />
add_filter('profile_update', 'MUO_AF_edit');<br />
add_action('the_content', 'MUO_AF_publish_post');<br />
</div></p>
<p>Then at the end of the file close the php tags with<br />
<div id="code_div">?></div></p>
<p>I have not been very descriptive in this tutorial of what the actual code within the plugin is doing because I created this tutorial wanting to show people the basics bit of code that are needed to call functions and make a plugin work.</p>
<p>I hope that you have learnt something by reading this tutorial and feel free to post a comment with your thoughts on this post.</p>


<p>Related posts:<ol><li><a href='http://www.thetutorialblog.com/php/twitter-like-pagination-using-codeigniter-and-jquery/' rel='bookmark' title='Permanent Link: Twitter-like pagination using CodeIgniter and jQuery'>Twitter-like pagination using CodeIgniter and jQuery</a> <small>If you use Twitter you'll notice that there is a...</small></li>
<li><a href='http://www.thetutorialblog.com/php/adding-security-to-codeigniter-forms-with-a-custom-library-class/' rel='bookmark' title='Permanent Link: Adding security to CodeIgniter forms with a custom library class'>Adding security to CodeIgniter forms with a custom library class</a> <small>The class that we are going to create within CI...</small></li>
<li><a href='http://www.thetutorialblog.com/cocoa-objective-c/creating-a-basic-ipad-application/' rel='bookmark' title='Permanent Link: Creating a basic iPad application'>Creating a basic iPad application</a> <small>Because of the recent announcement of the iPad more people...</small></li>
</ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/php/creating-a-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Installing Brushes in Photoshop</title>
		<link>http://www.thetutorialblog.com/photoshop/installing-brushes-in-photoshop/</link>
		<comments>http://www.thetutorialblog.com/photoshop/installing-brushes-in-photoshop/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 00:01:38 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[Photoshop]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[video tutorial]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=25</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphotoshop%2Finstalling-brushes-in-photoshop%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fphotoshop%2Finstalling-brushes-in-photoshop%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Installing Brushes in Photoshop" alt=" Installing Brushes in Photoshop" /><br />
			</a>
		</div>
<p><object width="480" height="392" data="http://flash.revver.com/player/1.0/player.swf?mediaId=959150&#038;affiliateId=42154" type="application/x-shockwave-flash" id="revvervideoa17743d6aebf486ece24053f35e1aa23"><param name="Movie" value="http://flash.revver.com/player/1.0/player.swf?mediaId=959150&#038;affiliateId=42154"></param><param name="FlashVars" value="allowFullScreen=true&#038;backColor=#000000&#038;frontColor=#ffffff&#038;gradColor=#000000"></param><param name="AllowFullScreen" value="true"></param><param name="AllowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://flash.revver.com/player/1.0/player.swf?mediaId=959150&#038;affiliateId=42154" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" flashvars="allowFullScreen=true&#038;backColor=#000000&#038;frontColor=#ffffff&#038;gradColor=#000000" allowfullscreen="true" width="480" height="392"></embed></object></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/photoshop/installing-brushes-in-photoshop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Increase Window Height and Width in Visual Basic</title>
		<link>http://www.thetutorialblog.com/visual-basic/increase-window-height-and-width-in-visual-basic/</link>
		<comments>http://www.thetutorialblog.com/visual-basic/increase-window-height-and-width-in-visual-basic/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 17:03:55 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[change]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vb]]></category>
		<category><![CDATA[width]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=24</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fvisual-basic%2Fincrease-window-height-and-width-in-visual-basic%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fvisual-basic%2Fincrease-window-height-and-width-in-visual-basic%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Increase Window Height and Width in Visual Basic" alt=" Increase Window Height and Width in Visual Basic" /><br />
			</a>
		</div>
<p><object width="480" height="392" data="http://flash.revver.com/player/1.0/player.swf?mediaId=937406&#038;affiliateId=42154" type="application/x-shockwave-flash" id="revvervideoa17743d6aebf486ece24053f35e1aa23"><param name="Movie" value="http://flash.revver.com/player/1.0/player.swf?mediaId=937406&#038;affiliateId=42154"></param><param name="FlashVars" value="allowFullScreen=true&#038;backColor=#000000&#038;frontColor=#ffffff&#038;gradColor=#000000"></param><param name="AllowFullScreen" value="true"></param><param name="AllowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://flash.revver.com/player/1.0/player.swf?mediaId=937406&#038;affiliateId=42154" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" flashvars="allowFullScreen=true&#038;backColor=#000000&#038;frontColor=#ffffff&#038;gradColor=#000000" allowfullscreen="true" width="480" height="392"></embed></object></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/visual-basic/increase-window-height-and-width-in-visual-basic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sliders in Cocoa/Objective C Xcode</title>
		<link>http://www.thetutorialblog.com/cocoa-objective-c/sliders-in-cocoaobjective-c-xcode/</link>
		<comments>http://www.thetutorialblog.com/cocoa-objective-c/sliders-in-cocoaobjective-c-xcode/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 23:31:57 +0000</pubDate>
		<dc:creator>Wez Pyke</dc:creator>
				<category><![CDATA[Cocoa/Objective-C]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[help]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[learn]]></category>
		<category><![CDATA[video tutorial]]></category>

		<guid isPermaLink="false">http://www.thetutorialblog.com/?p=22</guid>
		<description><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	A video tutorial showing the basics of cocoa/objective c and how to get the value of a slider. No related posts. Related posts brought to you by Yet Another Related Posts Plugin.


No related posts.

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[	<style>
	#code_div { border: 1px solid #DFF4B5; background-color: #F0FFD2; padding-left: 50px; padding:10px;}
	</style>
	
	<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fcocoa-objective-c%2Fsliders-in-cocoaobjective-c-xcode%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.thetutorialblog.com%2Fcocoa-objective-c%2Fsliders-in-cocoaobjective-c-xcode%2F&amp;source=wezpyke&amp;style=normal&amp;service=bit.ly" height="61" width="50" title="Sliders in Cocoa/Objective C Xcode" alt=" Sliders in Cocoa/Objective C Xcode" /><br />
			</a>
		</div>
<p>A video tutorial showing the basics of cocoa/objective c and how to get the value of a slider.</p>
<p><object width="480" height="392" data="http://flash.revver.com/player/1.0/player.swf?mediaId=826086&#038;affiliate=42154" type="application/x-shockwave-flash" id="revver82608612179007588853616"><param name="Movie" value="http://flash.revver.com/player/1.0/player.swf?mediaId=826086&#038;affiliate=42154"></param><param name="FlashVars" value="allowFullScreen=true"></param><param name="AllowFullScreen" value="true"></param><param name="AllowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://flash.revver.com/player/1.0/player.swf?mediaId=826086&#038;affiliate=42154" pluginspage="http://www.macromedia.com/go/getflashplayer" allowScriptAccess="always" flashvars="allowFullScreen=true" allowfullscreen="true" height="392" width="480"></embed></object></p>


<p>No related posts.</p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.thetutorialblog.com/cocoa-objective-c/sliders-in-cocoaobjective-c-xcode/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
