<?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>Joe Dolson Accessible Web Design &#187; Tutorials</title>
	<atom:link href="http://www.joedolson.com/articles/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joedolson.com/articles</link>
	<description>Tips and Commentary on Web Accessibility, Usability, and Search Marketing best practices.</description>
	<lastBuildDate>Sat, 13 Mar 2010 16:14:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Usable Category Navigation in Wordpress Pages</title>
		<link>http://www.joedolson.com/articles/2007/02/usable-category-navigation-in-wordpress-pages/</link>
		<comments>http://www.joedolson.com/articles/2007/02/usable-category-navigation-in-wordpress-pages/#comments</comments>
		<pubDate>Thu, 15 Feb 2007 16:55:11 +0000</pubDate>
		<dc:creator>Joe Dolson</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Blogging]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://www.joedolson.com/articles/2007/02/usable-category-navigation-in-wordpress-pages/</guid>
		<description><![CDATA[
Wordpress isn&#8217;t really designed to be used as a CMS.  It&#8217;s designed for blogging&#8201;&#8211;&#8201;nonetheless, it&#8217;s a surprisingly powerful little content management system, and with a little bit of tweaking you can pretty easily turn it into a nicely flexible&#160;system.



Read more about Wordpress&#160;Pages.



One of the challenges that needs to be dealt with is the use [...]<p><strong><a href="http://www.joedolson.com/articles/2007/02/usable-category-navigation-in-wordpress-pages/">Usable Category Navigation in Wordpress Pages</a></strong><br /><small>Copyright 2004&thinsp;&ndash;&thinsp;2010 Joseph C Dolson, Accessible Web Design</small></p>
]]></description>
			<content:encoded><![CDATA[<p>
Wordpress isn&#8217;t really designed to be used as a <acronym title="Content Management System">CMS</acronym>.  It&#8217;s designed for blogging&thinsp;&#8211;&thinsp;nonetheless, it&#8217;s a surprisingly powerful little content management system, and with a little bit of tweaking you can pretty easily turn it into a nicely flexible&nbsp;system.
</p>
<div class="aside">
<p>
<a href="http://codex.wordpress.org/Pages">Read more about Wordpress&nbsp;Pages.</a>
</p>
</div>
<p>
One of the challenges that needs to be dealt with is the use of Pages.  A &#8220;Page,&#8221; in Wordpress parlance, is a document which sits outside the blog chronology.  For the purpose of a <acronym title="Content Management System">CMS</acronym>, you don&#8217;t really want all of your posts to be chronologically organized.  You could rewrite the Post templates and the permalink format to eliminate all date information, which would provide you with a nice <acronym title="Content Management System">CMS</acronym>-like organization&thinsp;&#8211;&thinsp;but would also eliminate the blog function.  Realistically, you probably want&nbsp;both.
</p>
<p>
It&#8217;s very easy to create a large number of WordPress pages and sort them into a hierarchy. For presentation, the default WordPress function <code>wp_list_pages</code> creates a very nice nested group of unordered lists. This can be styled using <acronym title="Cascading Style Sheets">CSS</acronym> to create either a long list of pages with inset sub pages, or a fancy <acronym title="Cascading Style Sheets">CSS</acronym>-driven set of drop down or flyout&nbsp;menus.
</p>
<p>
So far, so good. If you&#8217;ve got 10 pages, a single list is fine.  But for larger sites, you&#8217;re running into other challenges. A straight list of your 150 pages is ugly, difficult to use, and difficult to&nbsp;navigate.
</p>
<p>
But the classic drop down or flyout menu has some usability issues.  For people with mobility impairments, for example, the ability to use a mouse may be limited&thinsp;&#8211;&thinsp;and it takes a fair amount of core source hacking in order to attach the javascript needed to make these menus completely keyboard navigable. It&#8217;s easy to make certain that the top level link in each category is usable from the keyboard&thinsp;&#8211;&thinsp;so your responsibility is to make certain that the top level category link will provide access to all sub&nbsp;pages.
</p>
<p>
Again, there&#8217;s an easy solution: write links to all your further pages into your document&nbsp;content.
</p>
<p>
Ick.  This solution sucks.  First of all, if you&#8217;re creating this site for a client, you can&#8217;t necessarily rely on them to retain the content you&#8217;ve carefully created.  Second, it&#8217;s very awkward to have to hand-maintain links to every page on the site.  Why are you using a <acronym title="Content Management System">CMS</acronym> if you&#8217;re going to have to do this&nbsp;anyhow?
</p>
<p>
Thankfully, although it&#8217;s not immediately obvious, Wordpress does provide a way to access the children of pages programmatically. Using this code, you can simply create a secondary navigation section which provides easily keyboard-navigable links to all pages below those top level&nbsp;documents.
</p>
<h4>The&nbsp;Code</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;h3&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'category'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/h3&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>get_the_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span> <span style="color: #339933;">,</span><span style="color: #0000ff;">''</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;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;child_of=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;title_li=&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>  
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;child_of=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;echo=0&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;title_li=&amp;child_of=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;sort_column=menu_order&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/ul&gt;;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>
What&#8217;s going on&nbsp;here?
</p>
<div class="aside">
<p>
<a href="http://codex.wordpress.org/Using_Custom_Fields">Read more about using Custom&nbsp;Fields.</a>
</p>
</div>
<p>
First up has really nothing to do with the navigation menu itself.  This is a header for the category navigation menu, arbitrarily placed in a level 3 heading element. It&#8217;s a little oddly phrased&thinsp;&#8211;&thinsp;this is because WordPress doesn&#8217;t provide access to Category labels for Pages the same way they do for Posts. Therefore, this is actually sourcing a Custom Field&thinsp;&#8211;&thinsp;a feature available in WordPress which gives you the ability to attahc any custom information to a document.  In this case, I&#8217;ve created a custom field named &#8220;category&#8221; which contains the phrase I wish to be considered the category for this item. Generally, it&#8217;s the link text of the top level link, although you could set it to be anything you&nbsp;wish.
</p>
<p>
We&#8217;re trying to talk about usability, however, so I&#8217;m inclined to suggest sticking to something&nbsp;appropriate.
</p>
<div class="aside">
<p>
Note that the code refers to the variables <code>$post</code> and <code>$post_parent</code>. It&#8217;s important to know that &#8220;Page&#8221; is a formality which indicates a post which resides outside the chronology&thinsp;&#8211;&thinsp;from a database management perspective, <em>everything</em> is a&nbsp;post.
</p>
</div>
<p>
The second block of code is a tricky bit.  This <code>if</code> query is checking to see whether the current page is a subpage of any other page.  In general, Wordpress has great built-in conditional functions&thinsp;&#8211;&thinsp;you can very easily check whether something is a page (<code>is_page()</code> or whether it&#8217;s a category page (<code>is_category()</code>. There isn&#8217;t, however, an <code>is_subpage()</code> condition.  So, this is the workaround&thinsp;&#8211;&thinsp;checking whether the current page is <em>not it&#8217;s own parent</em>. In Wordpress, pages at the top level of the hierarchy are their own parents. (Let&#8217;s not get into genetics, here&#8230;I&#8217;m&nbsp;concerned.)
</p>
<p>
Next we&#8217;ll use the normal <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages"><code>wp_list_pages()</code> function</a>. Again, we&#8217;re using the information about the post&#8217;s parent in order to determine what pages to list, using the <code>child_of</code> argument to retrieve only the Pages which are children of the current&nbsp;page.
</p>
<h4>Whoa, there!  I see a&nbsp;problem!</h4>
<p>
Yep, you sure do.  At this point, we&#8217;re only retrieving child navigation if we&#8217;re <em>not</em> on the top level page itself. Well, that&#8217;s great. You can get between child pages if you can find your way&nbsp;there!
</p>
<p>
So that second block of code comes into play. Same idea, except this time we&#8217;re fetching children of the current page, without checking whether the page is top level.  If it&#8217;s got children, great&thinsp;&#8211;&thinsp;we&#8217;ll display &#8216;em.  If it doesn&#8217;t&thinsp;&#8211;&thinsp;also great&thinsp;&#8211;&thinsp;we&nbsp;won&#8217;t.
</p>
<p>
This sytem does also work for multiple hierarchy levels, although it&#8217;s a bit awkward.  Here&#8217;s what you&#8217;ll get with three levels in the&nbsp;hierarchy:
</p>
<ul>
<li>Top level page, no children: displays category heading, no children. (The category heading could be removed using another conditional statement; I just haven&#8217;t done&nbsp;it.)</li>
<li>Top level page, with children: displays all descendants (children and grandchildren.) Grandchildren will be in a nested unordered list inside the list item for their&nbsp;parent.</li>
<li>Second level page, no children: displays all sibling pages (pages with the same&nbsp;parent).</li>
<li>Second level page, with children: displays all sibling pages AND displays the children of the current page, in a nested unordered list inside the list item for that&nbsp;page.</li>
<li>Third level page, no children: display all sibling pages at the grandchild&nbsp;level.</li>
</ul>
<p>And so on. This code functions in Wordpress versions 2.01 and&nbsp;above.</p>
<p><strong><a href="http://www.joedolson.com/articles/2007/02/usable-category-navigation-in-wordpress-pages/">Usable Category Navigation in Wordpress Pages</a></strong><br /><small>Copyright 2004&thinsp;&ndash;&thinsp;2010 Joseph C Dolson, Accessible Web&nbsp;Design</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.joedolson.com/articles/2007/02/usable-category-navigation-in-wordpress-pages/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Processing Forms with PHP, a Beginner&#8217;s Guide</title>
		<link>http://www.joedolson.com/articles/2007/02/processing-forms-with-php/</link>
		<comments>http://www.joedolson.com/articles/2007/02/processing-forms-with-php/#comments</comments>
		<pubDate>Tue, 06 Feb 2007 01:21:15 +0000</pubDate>
		<dc:creator>Joe Dolson</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.joedolson.com/articles/2007/02/processing-forms-with-php/</guid>
		<description><![CDATA[
Download PHP&#160;Script
The script includes a single file with the functioning script and form, a sample blank comma separated values file you can upload to your server, and the SQL statement to create the table for this script.  Otherwise, you&#8217;re on your&#160;own.

The beginning stages of a web-based form are very simple: you read the HTML [...]<p><strong><a href="http://www.joedolson.com/articles/2007/02/processing-forms-with-php/">Processing Forms with PHP, a Beginner&#8217;s Guide</a></strong><br /><small>Copyright 2004&thinsp;&ndash;&thinsp;2010 Joseph C Dolson, Accessible Web Design</small></p>
]]></description>
			<content:encoded><![CDATA[<div class="aside">
<p><a href="http://www.joedolson.com/scripts/form_processing.php">Download <acronym title="Hypertext PreProcessing">PHP</acronym>&nbsp;Script</a></p>
<p>The script includes a single file with the functioning script and form, a sample blank comma separated values file you can upload to your server, and the <acronym title="Structured Query Language (a database standard)">SQL</acronym> statement to create the table for this script.  Otherwise, you&#8217;re on your&nbsp;own.</p>
</div>
<p>The beginning stages of a web-based form are very simple: you read the <acronym title="HyperText Markup Language">HTML</acronym> guide, learn about select menus, options, form labels, radio inputs and all the myriad ways you can inveigle information from your visitors.  You also learn about the <code>action</code> and <code>method</code> attributes.  Great. So all of this <acronym title="HyperText Markup Language">HTML</acronym> you&#8217;ve learned is wonderful&thinsp;&#8211;&thinsp;but won&#8217;t actually <em>do</em> anything. You need to provide some kind of back-end rules to actually make any use of this&nbsp;information. </p>
<h4>Deciding how to use the&nbsp;Data</h4>
<p>First things first, you have to decide what you want to do with the data.  I&#8217;m only going to deal with the most common probable tasks, here&thinsp;&#8211;&thinsp;no image editing or complex database updates, just simple data management. Are you going to <a href="http://www.joedolson.com/articles/2007/02/processing-forms-with-php/#database">write your data to a database</a>?  Do you want to use it to <a href="http://www.joedolson.com/articles/2007/02/processing-forms-with-php/#file">create a file</a> which will hold a record of the transaction?  Do you want it to <a href="http://www.joedolson.com/articles/2007/02/processing-forms-with-php/#semail">send an email</a>?<br />
<span id="more-117"></span><br />
For the sake of each example, I&#8217;m going to imagine we&#8217;re creating a survey.  The form needs to submit information which will be inserted into a MySQL database which, if you choose, can be analyzed in various ways using other scripts later.  This is just about getting the data into the database.  We&#8217;ll start, therefore, by describing the form you&#8217;ll be using to collect&nbsp;information.</p>
<p>Let&#8217;s imagine a survey collecting four pieces of&nbsp;information:</p>
<ol>
<li>A reason for contacting you
<p>The reason for contact will have four options, but only one will be allowable as a choice.  This will use radio button&nbsp;inputs.</p>
</li>
<li>A list of services the contacting person might be interested in.
<p>In this case, the person will be able to select several options, so we&#8217;ll be using&nbsp;checkboxes.</p>
</li>
<li>Survey taker&#8217;s state of residence.
<p>This will be a drop down.  Only one can be chosen, but there are far too many choices for a radio input to make any&nbsp;sense.</p>
</li>
<li>Comments from the survey taker.
<p>Could be anything&thinsp;&#8211;&thinsp;so this will have to be a text&nbsp;field.</p>
</li>
</ol>
<p>The code for your form will look something like&nbsp;this:</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>Why are you contacting us?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1_why&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1a&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1a&quot;</span>&gt;</span>Technical Support<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1_why&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1b&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1b&quot;</span>&gt;</span>Applying for Work<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1_why&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1c&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1c&quot;</span>&gt;</span>Wanted to Hire You<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1_why&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1d&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q1d&quot;</span>&gt;</span>Other<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>What service are you interested in? (Check all that apply.)<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2_service[]&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2a&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Heating&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2a&quot;</span>&gt;</span>Heating<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2_service[]&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2b&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Cooling&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2b&quot;</span>&gt;</span>Cooling<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2_service[]&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2c&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Plumbing&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2c&quot;</span>&gt;</span>Plumbing<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2_service[]&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2d&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Wiring&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2d&quot;</span>&gt;</span>Wiring<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2_service[]&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2e&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Carpentry&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q2e&quot;</span>&gt;</span>Carpentry<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>Where are you from?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q3&quot;</span>&gt;</span>Pick your state:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q3&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q3_state&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;none&quot;</span>&gt;</span>Choose One<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;MN&quot;</span>&gt;</span>Minnesota<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;MT&quot;</span>&gt;</span>Montana<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;NY&quot;</span>&gt;</span>New York<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>Comments<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q4&quot;</span>&gt;</span>Please provide additional comments about our services.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">textarea</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q4&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;q4_comments&quot;</span> <span style="color: #000066;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #000066;">cols</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;40&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">textarea</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span>&gt;</span>Submit the form<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Send your Input&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>This form will be the centerpiece of our example form processing&nbsp;script.</p>
<h4>Creating your Form and your&nbsp;Script</h4>
<p>Regardless of your chosen method of using data, you&#8217;ll need to have a script which collects the information from the form. This can be the same for each processing choice&thinsp;&#8212;&thinsp;first gather all data, then build the final element which either sends your email, inputs data to your database, or adds information to your data&nbsp;file.</p>
<div class="aside">
<p><strong>What happens if you leave the action attribute blank in a&nbsp;form?</strong></p>
<p>The form will submit to itself&thinsp;&#8211;&thinsp;that is, the page which holds the form will be used to process the form information.  In <acronym title="Hypertext PreProcessing">PHP</acronym>, this simply requires you to add your form processing code to that page.  This is a workable way of handling form data for a simple isolated form, but leaving the <code>action</code> attribute empty is not valid under the <acronym title="HyperText Markup Language">HTML</acronym> 4.01 or <acronym title="eXtensible HyperText Markup Language - HTML reformulated as XML">XHTML</acronym> 1.0 doctypes. To have a page process itself, it&#8217;s preferable to use the <acronym title="Hypertext PreProcessing">PHP</acronym> global variable <code>$_SERVER['PHP_SELF']</code>, which will supply the current file&nbsp;name. </p>
<p><ins datetime="2008-06-30T10:58:00">You don&#8217;t, however, want to use this global variable &#8220;in the raw.&#8221; To make it a bit safer, you&#8217;ll want to do something more like <code>htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES)</code>, which will strip out some potentially harmful attacks. It&#8217;s not infallible; but it&#8217;s better than using <code>PHP_SELF</code> by itself!</ins></p>
</div>
<p>There are two general types of form submission methods&thinsp;&#8211;&thinsp;<code>POST</code> and <code>GET</code>. Both are useful, but in this case I&#8217;ll only be dealing with POST data.  If you want to learn more about the differences between the GET and POST methods, you might want to read an <a href="http://www.cs.tut.fi/~jkorpela/forms/methods.html">article describing the difference</a> at length.  You&#8217;ll notice that the code above has had the <code>method</code> attribute set to <code>POST</code>.  The other important attribute for forms, <code>action</code> has been left blank for&nbsp;now.</p>
<p>In the course of this article, we&#8217;re going to build a script to process this example form&thinsp;&#8211;&thinsp;our script will be called <code>process.php</code>.  For simplicity, we&#8217;ll contain the entire script in a single page.  The form itself and all the processing commands will be contained in one&nbsp;page.</p>
<h4>The First Pass: Retrieving the&nbsp;Variables</h4>
<p>Opening the&nbsp;script:</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;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// HANDLE THE INPUT</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>We&#8217;ve established the outermost boundaries of our data processing.  This snippet initiates <acronym title="Hypertext PreProcessing">PHP</acronym>, establishes a simple <code>if</code> logical query which checks whether the form has been submitted.  The data following the double forward slash? Just a comment.  Anything on the same line as a double slash is a comment&thinsp;&#8211;&thinsp;<acronym title="Hypertext PreProcessing">PHP</acronym> ignores&nbsp;it. </p>
<p>One of the most important things to consider when retrieving data from a publicly available web form is whether you can <em>trust</em> the data.  And the most important thing to realize when you&#8217;re considering this is that <em>you can never trust public input</em>. <em>Never</em>. Part of having a form online is the acknowledgement that whether through malice, incompetence, or accident, there will always be the possibility that your form will be used to send data other than what you intended.  You should take precautions, therefore, to check every piece of information that comes your&nbsp;way.</p>
<p>Text fields are the easiest fields to retrieve, but can be tricky to examine.  For more information on <acronym title="Hypertext PreProcessing">PHP</acronym> security, I highly recommend reading <a href="http://www.addedbytes.com/php/writing-secure-php/">Dave Child&#8217;s &#8220;Writing Secure <acronym title="Hypertext PreProcessing">PHP</acronym>&#8221;</a> or ordering a book specifically on the subject, such as <a href="http://www.amazon.com/exec/obidos/ASIN/1590595084/joedolsonacce-20">Pro <acronym title="Hypertext PreProcessing">PHP</acronym> Security</a> by Chris Snyder and Michael Southwell. I&#8217;ll touch lightly on the subject; but don&#8217;t count on this script for any serious&nbsp;security.</p>
<p>So what needs to go inside that commented space?  We&#8217;ll need to collect the information which was placed in the form, check and make sure it&#8217;s the type of information we were looking for, and then we&#8217;ll assign each piece of data to a variable which we can use to format our final&nbsp;result.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$q1_why</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q1_why'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$q2_service</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q2_service'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$q3_state</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q3_state'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$q4_comments</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q4_comments'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Pretty straightforward&thinsp;&#8211;&thinsp;we&#8217;re taking the raw information from the form submission and assigning them to variables. Every piece of data sent from a form using the POST method will be stuck into <acronym title="Hypertext PreProcessing">PHP</acronym>&#8217;s $_POST array variable, retrievable using the <code>name</code> attribute of the form input. You&#8217;ll notice one thing here which doesn&#8217;t seem to quite match&thinsp;&#8211;&thinsp;the name attribute for question 2 was actually &#8220;q2_service[].&#8221;  What do the square brackets mean?  They mean that this input, when submitted, will be placed in a variable of type <code>array</code> as well.  This is what allows you to retrieve multiple answers from this question&thinsp;&#8211;&thinsp;everything checked off is now associated with the $q3_service array&nbsp;variable.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$q3_state</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q4_comments</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$q4_comments</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q4_comments</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$q4_comments</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q4_comments</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q1_why</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> 
<span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q2_service</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> 
<span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q3_state</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> 
<span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q4_comments</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> 
<span style="color: #000088;">$error</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;">$process</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">TRUE</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: #000088;">$process</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Slightly more complicated.  I&#8217;ve elected to skip examining the data for questions 1 and 2, because they are defined within the form.  There&#8217;s relatively little chance that they&#8217;re being faked.  Nonetheless, in a production script you may well want to inspect them. I am going to check questions 3 and 4, however.  Question 3 could be a problem because the default option is &#8220;None.&#8221; In this script, we&#8217;re going to insist that our visitors be from one of these three states.  In a real situation, you may want to allow for some other possibility&thinsp;&#8211;&thinsp;but not today.  We&#8217;re checking to see whether our visitor has failed to pick their state.  If so, we&#8217;ll set the variable <code>$error</code> equal to the boolean value &#8220;TRUE,&#8221; which we&#8217;ll use later to trigger an error&nbsp;condition.</p>
<p>With question 4, we don&#8217;t really care what the content is&thinsp;&#8211;&thinsp;but we don&#8217;t want any extra spaces and we REALLY don&#8217;t want anybody submitting <acronym title="HyperText Markup Language">HTML</acronym> formatted text.  So we&#8217;re using the <code>trim()</code> function to strip white space and the <code>strip_tags()</code> function to remove <acronym title="HyperText Markup Language">HTML</acronym>&nbsp;code.</p>
<p>Question 2 may have multiple parts.  If the user can submit multiple choices, there&#8217;s always a possibility that these multiple parts will need to be dealt with&thinsp;&#8211;&thinsp;we can&#8217;t just send the array around directly.  We&#8217;ll need to turn this array of answers into specific&nbsp;parts.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$q2_service</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$q2_services</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;[&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$val</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;]&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This code loops through the array of services selected and creates a string variable with each element contained in square brackets.  This doesn&#8217;t serve any programmatic purpose except to make it easy to distinguish one element from another when viewing your final&nbsp;results.</p>
<p>Finally, we string everything together&thinsp;&#8211;&thinsp;make sure every variable has been set and that <code>$error</code> is FALSE, indicating that no error has occurred. If everything&#8217;s OK, we&#8217;ll set the value of $process to TRUE and we&#8217;ll move on to actually do something with this&nbsp;information.</p>
<h4 id="database">Writing Form Data to a MySQL&nbsp;Database</h4>
<p>The first task you&#8217;ll need to accomplish is to create your database.  This won&#8217;t necessarily be available on every hosting solution. If you&#8217;re using one of the major hosting services, such as GoDaddy, you can always refer to their <a href="http://help.godaddy.com/article_list.php?topic_id=67">extensive documentation</a> on databases.  One of your first steps should always be going to your host&#8217;s help pages&thinsp;&#8211;&thinsp;any luck, and they&#8217;ll provide documentation like this which may answer a number of your questions on setting up a database.  Regardless of your hosting service, however, if you use MySQL you will have to deal with the language which defines and interacts with the database&thinsp;&#8211;&thinsp;<acronym title="Structured Query Language (a database standard)">SQL</acronym>, or Structured Query&nbsp;Language. </p>
<p>It&#8217;s well beyond the scope of this article to try and articulate the complete nature of MySQL or Structured Query Language.  To get started learning <acronym title="Structured Query Language (a database standard)">SQL</acronym>, you may want to give a look to the articles available from the <a href="http://www.w3schools.com/sql/sql_intro.asp">W3Schools&#8217; <acronym title="Structured Query Language (a database standard)">SQL</acronym>&nbsp;Tutorial</a>.</p>
<p>However, the minimum you&#8217;ll need will be a single database table with five fields.  I&#8217;m actually going to go to six, because I like to attach a timestamp to every form submission&thinsp;&#8211;&thinsp;this information can really make your data a lot more&nbsp;useful.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">TABLE</span> survey <span style="color: #FF00FF;">&#40;</span>
sid <span style="color: #999900; font-weight: bold;">INT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span> <span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #990099; font-weight: bold;">PRIMARY KEY</span><span style="color: #000033;">,</span> 
q1_why <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">127</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span> 
q2_service <span style="color: #999900; font-weight: bold;">TEXT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span> 
q3_state <span style="color: #999900; font-weight: bold;">VARCHAR</span><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">2</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span> 
q4_comments <span style="color: #999900; font-weight: bold;">TEXT</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #000033;">,</span> 
time_stamp <span style="color: #999900; font-weight: bold;">TIMESTAMP</span> <span style="color: #CC0099; font-weight: bold;">NOT</span> <span style="color: #9900FF; font-weight: bold;">NULL</span><span style="color: #FF00FF;">&#41;</span> 
<span style="color: #990099; font-weight: bold;">TYPE</span> <span style="color: #CC0099;">=</span> MYISAM<span style="color: #000033;">;</span></pre></div></div>

<p>This <acronym title="Structured Query Language (a database standard)">SQL</acronym> code will create your basic MySQL table with six fields.  It&#8217;ll contain an automatically incremented unique ID, create space for your fields, and keep track of when the submission occurred.  For more explanations of databases, try <a href="http://www.mysql.com">the MySQL home page</a> or consider reading a complete guide to MySQL such as <a href="http://www.amazon.com/exec/obidos/ASIN/0072224770/joedolsonacce-20">MySQL&trade;: The Complete Reference</a>, by Vikram&nbsp;Vaswani.</p>
<p>Creating the database is somewhat outside the range of what I&#8217;m trying to cover, however.  Hopefully the references provided will help you out&thinsp;&#8211;&thinsp;but for now, we&#8217;re going to have to deal with getting information <em>into</em> the database.  This, of course, will require a completely different, though related, <acronym title="Structured Query Language (a database standard)">SQL</acronym>&nbsp;query.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_USER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'yourusername'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_PASSWORD'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'yourpassword'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_HOST'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DB_NAME'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'your_database'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$dbc</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">mysql_connect</span> <span style="color: #009900;">&#40;</span>DB_HOST<span style="color: #339933;">,</span> DB_USER<span style="color: #339933;">,</span> DB_PASSWORD<span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Failure: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span>DB_NAME<span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Could not select database: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Before you can start adding information to a database, you need to attach your script to the database.  In order for it to do that, you need to supply that script with your username, your password, and the name of your database.  Now, obviously, this is a security issue.  You should never make this information easily accessible&thinsp;&#8211;&thinsp;if possible, place this information in a separate file with a difficult to guess filename, somewhere below your website&#8217;s root directory.  You can then <code>include</code> your database&nbsp;connection:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;../mydb_connect1597.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>In this case, the connection file has been included one directory below the active script. Having connected to your database, you can move on and insert your&nbsp;data.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO survey VALUES ('','<span style="color: #006699; font-weight: bold;">$q1_why</span>','<span style="color: #006699; font-weight: bold;">$q2_services</span>','<span style="color: #006699; font-weight: bold;">$q3_state</span>','<span style="color: #006699; font-weight: bold;">$q4_comments</span>','now()')&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$q</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>That&#8217;s all the <acronym title="Hypertext PreProcessing">PHP</acronym> code required to insert the information from your form into a database.  Now, you probably want to check that the data was correctly inserted, as&nbsp;well.</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: #339933;">!</span><span style="color: #000088;">$q</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;MySQL Insertion failure.&lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</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: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//for testing only</span>
<span style="color: #666666; font-style: italic;">//echo &quot;&lt;p&gt;MySQL Insertion Successful&lt;/p&gt;&quot;;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This code will simply check whether the <code>mysql_query</code> was performed successfully, and notify you of the results. It also closes the database connection, since you no longer need it in this instance of the&nbsp;script.</p>
<p>That&#8217;s something like the bare minimum needed to process a form and insert the data into a MySQL database&thinsp;&#8211;&thinsp;there are scads of issues not dealt with, including many database security issues and error handling. But that&#8217;s a question for a later&nbsp;article.</p>
<h4 id="file">Placing your data in a&nbsp;file</h4>
<p>As long as you know the correct data format, you can create just about any type of file using <acronym title="Hypertext PreProcessing">PHP</acronym>.  The easiest, of course, are <code>.txt</code> and <code>.csv</code> files.  Comma separated values files tend to be a bit more useful for this kind of thing, since you can then open the file in a program such as Microsoft Excel and be able to sort the information.  Although it&#8217;s possible to create the file from the beginning with <acronym title="Hypertext PreProcessing">PHP</acronym>, it&#8217;s much easier to simply create the file in advance.  You can create a .csv format file in any text editor&thinsp;&#8211;&thinsp;simply open a blank document and save it as &#8220;survey.csv&#8221;&thinsp;&#8211;&thinsp;the quotes will be required if you&#8217;re using Microsoft&#8217;s&nbsp;Notepad.</p>
<p>Servers are protective of files.  Naturally, they don&#8217;t want to leave every file just sitting there waiting for <em>anybody</em> to edit it.  In order to prevent this, files have <em>permissions settings</em>. Each file has permissions set for three users: the owner, the group, and the WORLD&thinsp;&#8211;&thinsp;which is to say, everybody. Each user is granted specific permissions for three actions: read, write, and execute.  Most of the time, you want everybody to be able to read your documents, but only want yourself to be able to write them.  For scripts and files which will be recording data, however, you need to be a little more trusting. For more on file permissions, read &#8220;<a href="http://www.dartmouth.edu/~rc/help/faq/permissions.html"> Understanding file permissions on Unix: a brief&nbsp;tutorial</a>.&#8221;</p>
<p>Permissions are represented most commonly in 9 character strings.  Each set of three characters represents one user, and each character within that user represents one behavior.  For example, the permissions set <code>rwxrw-r-x</code> gives the owner of the file permission to read it, write it, and execute it.  The group can read and write, and the world can read and execute the&nbsp;file. </p>
<p>You need to make certain that your .csv file has permissions set which will allow your script to read it and write it.  The script probably runs with group permissions, but in some servers it may require world-wide permissions&thinsp;&#8211;&thinsp;if <acronym title="Hypertext PreProcessing">PHP</acronym> is running under a different group than the owner of the&nbsp;file.</p>
<p>The&nbsp;code:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$csv_file</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'survey.csv'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_writable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$csv_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$csv_handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$csv_file</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// this line is for troubleshooting</span>
<span style="color: #666666; font-style: italic;">// echo &quot;&lt;p&gt;Cannot open file $csv_file&lt;/p&gt;&quot;;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You&#8217;ve defined a file pointer which can find the comma separated values file you created.  You&#8217;re checking it to see whether it&#8217;s readable and, while you&#8217;re testing, you&#8217;re providing an error message to tell you what&#8217;s going&nbsp;wrong.</p>
<div class="aside">
<p><strong>About Error&nbsp;Messages</strong></p>
<p>You don&#8217;t want to provide technical error messages in a production setting&thinsp;&#8211;&thinsp;when you&#8217;re live, you need to focus on telling your users what they need to know and nothing more.  Giving away technical information is an invitation to hackers and means nothing to the average&nbsp;user.</p>
</div>
<p>At this point, you&#8217;ve also opened the file for editing using the function <code>fopen</code>.  This function accepts two arguments: the first has to be a file pointer.  The second is a code which represents the manner in which you&#8217;re opening the file&thinsp;&#8211;&thinsp;you need to tell the script whether you want to overwrite the existing content of the file, whether you want to add information at the beginning of the file or the end, or whether you don&#8217;t intend to write to the file at&nbsp;all.  </p>
<p>The <acronym title="Hypertext PreProcessing">PHP</acronym> online manual has a complete list of this codes at <a href="http://us3.php.net/manual/en/function.fopen.php">the <code>fopen</code> function page</a>. For now, however, just know that <code>a</code> means &#8220;Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it.&#8221; We&#8217;re not interested in reading the information and we don&#8217;t want to overwrite anything that&#8217;s already there, so it&#8217;s to the end of the file we&nbsp;go.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$csv_item</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$q1_why</span><span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$q2_services</span><span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$q3_state</span><span style="color: #000099; font-weight: bold;">\&quot;</span>,<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$q4_comments</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_writable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$csv_file</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$csv_handle</span><span style="color: #339933;">,</span> <span style="color: #000088;">$csv_item</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: #666666; font-style: italic;">//for testing</span>
<span style="color: #666666; font-style: italic;">//echo &quot;Cannot write to file&quot;;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$csv_handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This script creates a text string containing the four variables, checks to see whether the file is writable, and writes the string into the file.  It then closes the file by releasing the file handler you&#8217;ve created and exits the script.  The information has been saved to your file for later&nbsp;reading.</p>
<h4 id="semail">Sending your Information by&nbsp;Email</h4>
<p>In some ways, this is the easiest method.  It will simply stick the information into an email message and send it to you. What it doesn&#8217;t do is keep a running list of the uses of the form&thinsp;&#8211;&thinsp;if you wanted to use this for a survey, for example, you&#8217;d be manually entering the information from each survey submission into your chosen method of data&nbsp;tracking. </p>
<p>There are four basic elements required to send mail with <acronym title="Hypertext PreProcessing">PHP</acronym>.  The entire process is handled by a function called, predictably enough, <code>mail()</code>. This function needs four&nbsp;arguments:</p>
<ol>
<li>The destination address, or&nbsp;recipient.</li>
<li>The message&nbsp;subject.</li>
<li>The message content, or&nbsp;body.</li>
<li>Mail header&nbsp;information.</li>
</ol>
<p>Technically speaking, the mail headers are optional information.  However, I think they&#8217;re important and valuable so we&#8217;re going to go ahead and pretend that they&#8217;re&nbsp;required.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//first, define your four mail function fields</span>
<span style="color: #000088;">$recipient</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;you@yourdomain.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Online Survey from Your Domain&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Online Survey:<span style="color: #000099; font-weight: bold;">\n</span>
Why are you contacting us? <span style="color: #006699; font-weight: bold;">$q1_why</span><span style="color: #000099; font-weight: bold;">\n</span>
What services are you interested in? <span style="color: #006699; font-weight: bold;">$q2_services</span><span style="color: #000099; font-weight: bold;">\n</span>
Where are you from? <span style="color: #006699; font-weight: bold;">$q3_state</span><span style="color: #000099; font-weight: bold;">\n</span>
Your Comments:<span style="color: #000099; font-weight: bold;">\n</span>
<span style="color: #006699; font-weight: bold;">$q4_comments</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: YourSurvey &lt;survey@domain.com&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Reply-To: survey@domain.com<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is pretty straightforward&thinsp;&#8211;&thinsp;each field is a basic text string.  To make it easier to read and understand, I&#8217;m writing the questions asked into the message before the variable with the answers.  I&#8217;m also making use of <code>\n</code>&thinsp;&#8211;&thinsp;this code creates a new line in the message, and will make the results much easier to process. (It has the same effect above in the <a href="#files">CSV files&nbsp;section</a>.)</p>
<p>You can name the sending address whatever you&#8217;d like, but I&#8217;d recommend using a name which will make it easy to associate the messages sent with this particular&nbsp;script.</p>
<p>Having assigned these variables, all that&#8217;s left is to send the&nbsp;message:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$recipient</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">exit</span><span style="color: #339933;">;</span></pre></div></div>

<p>And you&#8217;re done.  You&#8217;ve processed your&nbsp;data.</p>
<h3>Conclusion</h3>
<p>In conclusion, this is a very sparse way of addressing the complicated issue of letting people use your site interactively. It hardly touches on any of the major issues of usability or security, such as protecting your scripts from use by spammers; preventing hackers from accessing your databases; returning user-friendly error messages; or any higher level data processing.  But it&#8217;s intended to be basic&thinsp;&#8211;&thinsp;this is just an introduction.  Once you&#8217;ve gotten your feet wet, you should really look into a solid textbook which will cover some of the more difficult&nbsp;issues.</p>
<h3>Recommended&nbsp;Reading</h3>
<ul>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/0596101104/joedolsonacce-20">Learning <acronym title="Hypertext PreProcessing">PHP</acronym> and MySQL</a>, by Michele E. Davis and Jon A.&nbsp;Phillips</li>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/0672329166/joedolsonacce-20"><acronym title="Hypertext PreProcessing">PHP</acronym> and MySQL Web Development</a>, by Luke Welling and Laura&nbsp;Thomson</li>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/1590598628/joedolsonacce-20">Beginning <acronym title="Hypertext PreProcessing">PHP</acronym> and MySQL 5: From Novice to Professional</a>, by W. Jason&nbsp;Gilmore</li>
<li><a href="http://www.amazon.com/exec/obidos/ASIN/1590595084/joedolsonacce-20">Pro <acronym title="Hypertext PreProcessing">PHP</acronym> Security</a>, by Chris Snyder and Michael&nbsp;Southwell</li>
</ul>
<p>I know that I&#8217;ve mentioned that Pro <acronym title="Hypertext PreProcessing">PHP</acronym> Security book already&thinsp;&#8212;&thinsp;but I can&#8217;t emphasize the importance of security enough.  By putting a form on your site and inviting any kind of input from your visitors, you&#8217;re creating a doorway into your website.  Most of the time you&#8217;ll be fine, even if you haven&#8217;t taken the precautions you should&thinsp;&#8212;&thinsp;but it&#8217;s not worth the risk if you have the opportunity to protect yourself.
<p><strong><a href="http://www.joedolson.com/articles/2007/02/processing-forms-with-php/">Processing Forms with <acronym title="Hypertext PreProcessing">PHP</acronym>, a Beginner&#8217;s Guide</a></strong><br /><small>Copyright 2004&thinsp;&ndash;&thinsp;2010 Joseph C Dolson, Accessible Web&nbsp;Design</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.joedolson.com/articles/2007/02/processing-forms-with-php/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>Internet Explorer 7: Irritation of the Day</title>
		<link>http://www.joedolson.com/articles/2006/09/internet-explorer-7-irritation-of-the-day/</link>
		<comments>http://www.joedolson.com/articles/2006/09/internet-explorer-7-irritation-of-the-day/#comments</comments>
		<pubDate>Thu, 21 Sep 2006 16:05:24 +0000</pubDate>
		<dc:creator>Joe Dolson</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.joedolson.com/articles/2006/09/internet-explorer-7-irritation-of-the-day/</guid>
		<description><![CDATA[
This post has nothing to do with IE7&#8217;s support for CSS, adherence to web standards, or general functionality.  Instead, it&#8217;s a general complaint about one specific annoyance:  why did Microsoft&#8217;s IE development team want IE7 to&#160;&#8220;click&#8221;?


I mean, as a marketing metaphor, it&#8217;s great.  Everybody wants their product to &#8220;click&#8221;.  However, in [...]<p><strong><a href="http://www.joedolson.com/articles/2006/09/internet-explorer-7-irritation-of-the-day/">Internet Explorer 7: Irritation of the Day</a></strong><br /><small>Copyright 2004&thinsp;&ndash;&thinsp;2010 Joseph C Dolson, Accessible Web Design</small></p>
]]></description>
			<content:encoded><![CDATA[<p>
This post has nothing to do with <acronym title="internet explorer, version 7">IE7</acronym>&#8217;s support for <acronym title="Cascading Style Sheets">CSS</acronym>, adherence to web standards, or general functionality.  Instead, it&#8217;s a general complaint about one specific annoyance:  why did Microsoft&#8217;s <acronym title="Internet Explorer">IE</acronym> development team want IE7 to&nbsp;&#8220;click&#8221;?
</p>
<p>
I mean, as a marketing metaphor, it&#8217;s great.  Everybody wants their product to &#8220;click&#8221;.  However, in this case I think they&#8217;ve taken it a bit too&nbsp;literally.
</p>
<p><span id="more-72"></span></p>
<h3>The&nbsp;Problem</h3>
<p>
On installation, IE7 automatically turns on the Windows Explorer click sound&thinsp;&#8211;&thinsp;this effect a wide variety of actions, particularly including opening folders and <em>clicking on links</em>.  Believe it or not, these are activities I do a lot&thinsp;&#8211;&thinsp;but I like them&nbsp;silent.
</p>
<p>
One of the first things I always do with a new computer is turn off <strong>all</strong> of the default sounds.  So why does IE7 think that upgrading Internet Explorer also means I&#8217;ve changed my normal preferences about&nbsp;sounds?
</p>
<p>
I have trouble thinking of many reasons this would be done which make any serious&nbsp;sense:
</p>
<ol>
<li>It&#8217;s a bug.  Somehow, all the bug testers have their sounds turned on and nobody ever noticed this. Alternately, it actually occurs very rarely&thinsp;&#8211;&thinsp;but somehow has occurred to me on all three of my computers every single time I&#8217;ve installed it, with every beta version or release candidate I&#8217;ve looked&nbsp;at.</li>
<li>It&#8217;s a feature.  IE7 comes with a BRAND NEW Windows Explorer click sounds, and they want to make sure everybody gets to hear&nbsp;it.</li>
<li>It&#8217;s a feature.  They&#8217;re concerned that some users may not notice that they&#8217;ve clicked on links in web pages unless they receive an aural notification.  (This is, of course, true&thinsp;&#8211;&thinsp;however, those users undoubtedly are using screen readers&nbsp;anyhow.)</li>
<li>It&#8217;s not really happening.  It&#8217;s entirely in my imagination, since I&#8217;m obviously searching for excuses to be upset with&nbsp;Microsoft.</li>
</ol>
<p>
The most probable of these is that it&#8217;s actually a rare bug&thinsp;&#8211;&thinsp;but given the number of times it&#8217;s happened to me, I&#8217;m personally disinclined to consider that.  The idea that the development would intentionally program some &#8220;feature&#8221; in IE7 which actively alters a user&#8217;s settings, however, is sounding quite likely. But&nbsp;why?
</p>
<h3>The&nbsp;Solution</h3>
<p>
Assuming that you haven&#8217;t been won over by IE7&#8217;s fabulous clicking sound, you may want to turn it off.  Well, actually this is exceptionally simple&thinsp;&#8211;&thinsp;it&#8217;s just silly that you have to do it at&nbsp;all.
</p>
<p>
On Windows XP&nbsp;SP2:
</p>
<ol>
<li>Control Panel&nbsp;&rarr;</li>
<li>Sounds and Audio Devices&nbsp;&rarr;</li>
<li>Sounds&nbsp;&rarr;</li>
<li>Select &#8220;Start Navigation&#8221; in the <em>Program Events</em> selection area&nbsp;&rarr;</li>
<li>Select your sound of choice (&#8220;None&#8221;, for example) from the drop down menu below.&nbsp;&rarr;</li>
<li>Click&nbsp;&#8220;OK&#8221;</li>
</ol>
<p>
If you like the &#8220;No Sounds&#8221; option, like me, you can do this more quickly. You&#8217;ll just want to switch your Sound scheme to the default setting briefly, then switch it back to &#8220;No Sounds&#8221;.  That&#8217;ll turn everything on and off&thinsp;&#8211;&thinsp;kind of like a cold reboot for your sound&nbsp;scheme.
</p>
<p><strong><a href="http://www.joedolson.com/articles/2006/09/internet-explorer-7-irritation-of-the-day/">Internet Explorer 7: Irritation of the Day</a></strong><br /><small>Copyright 2004&thinsp;&ndash;&thinsp;2010 Joseph C Dolson, Accessible Web&nbsp;Design</small></p>]]></content:encoded>
			<wfw:commentRss>http://www.joedolson.com/articles/2006/09/internet-explorer-7-irritation-of-the-day/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
	</channel>
</rss>
