<?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>Web Cash &#187; function</title>
	<atom:link href="http://www.earn-web-cash.com/tag/function/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.earn-web-cash.com</link>
	<description>Writing, Designing, and Making Money Online</description>
	<lastBuildDate>Sun, 04 Dec 2011 22:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Javascript Function: Random Number Generator</title>
		<link>http://www.earn-web-cash.com/2008/02/24/random-number-function/</link>
		<comments>http://www.earn-web-cash.com/2008/02/24/random-number-function/#comments</comments>
		<pubDate>Sun, 24 Feb 2008 20:07:28 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Game Design]]></category>
		<category><![CDATA[JS Tutorials]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/24/random-number-function/</guid>
		<description><![CDATA[Yesterday, I wrote a short article on generating random numbers in Javascript. The Javascript random number generator is similar to C/++ &#8211; it gives you a random number from 0 to 1 and you need to make it useful. At the suggestion of a reader (thanks Justin), I decided to go ahead and turn the [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I wrote a short <a href="http://www.earn-web-cash.com/2008/02/23/random-number-javascript/">article on generating random numbers in Javascript</a>.  The Javascript random number generator is similar to C/++ &#8211; it gives you a random number from 0 to 1 and you need to make it useful.</p>
<p>At the suggestion of a reader (thanks Justin), I decided to go ahead and turn the general formula for this into a short helper function to generate a random number.<br />
<span id="more-158"></span></p>
<h4>Random Numbers: General Formula</h4>
<p>First, let&#8217;s take a minute and recap the general formula for finding a random number.</p>
<p>Javascript&#8217;s Math.random() method returns a random number between 0 and 1.  By multiplying this decimal value by a whole number, we can generate a desired range of values.  For example, by multiplying Math.random()&#8217;s result by 10, we get a range of 0 to 10.</p>
<p>Next, we take the Math.floor value of that random number.  This gives us just the integer portion &#8211; and it effectively cuts our range to 0 through 9.  Finally, we can modify this by adding an offset number.  So if we wanted a random number between 51 and 60, we&#8217;d add 51 to that result.</p>
<h4>Creating a Random Number Function</h4>
<p>The basic formula we end up with is&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span>Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> setSize<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> setOffset<span style="color: #339933;">;</span></pre></div></div>

<p>Our code would be much more readable if we had a helper function that could be called like this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">randomNumber <span style="color: #339933;">=</span> rand<span style="color: #009900;">&#40;</span>min<span style="color: #339933;">,</span> max<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Our function is going to take two parameters &#8211; min and max.  From these two parameters, we can calculate the offset and the set size and generate the proper random number.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> rand<span style="color: #009900;">&#40;</span>min<span style="color: #339933;">,</span> max<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> offset <span style="color: #339933;">=</span> min<span style="color: #339933;">;</span>
  <span style="color: #003366; font-weight: bold;">var</span> range <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>max <span style="color: #339933;">-</span> min<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #003366; font-weight: bold;">var</span> randomNumber <span style="color: #339933;">=</span> Math.<span style="color: #660066;">floor</span><span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> range<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> offset<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">return</span> randomNumber<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>All done.</p>
<p>Add that function to a utility file, and you&#8217;ve got a handy random number generator at your disposal.  It even uses the same format as PHP&#8217;s rand() function, to help increase consistency and readability in your code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/24/random-number-function/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Create a Random Password for Users</title>
		<link>http://www.earn-web-cash.com/2008/02/01/random-password/</link>
		<comments>http://www.earn-web-cash.com/2008/02/01/random-password/#comments</comments>
		<pubDate>Fri, 01 Feb 2008 21:56:49 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[password]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[user]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/01/random-password/</guid>
		<description><![CDATA[If you're working on a user-management system, you may find it useful to be able to create a random password for users.

Some systems generate these initially and have the user log in to set a permanent password.  You might also have a "Reset" button, where the script generates a random password and e-mails it to the user.

This quick tutorial will show you how to create an 8 character random password containing a mix of letters and numbers.  Or, if you're impatient, jump straight to the <a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/randpassword.txt' title='Random Password Generator'>function's source code</a>]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re working on a user-management system, you may find it useful to be able to create a random password for users.</p>
<p>Some systems generate these initially and have the user log in to set a permanent password.  You might also have a &#8220;Reset&#8221; button, where the script generates a random password and e-mails it to the user.</p>
<p>This quick tutorial will show you how to create an 8 character random password containing a mix of letters and numbers.  Or, if you&#8217;re impatient, jump straight to the <a href='http://www.earn-web-cash.com/wp-content/uploads/2008/02/randpassword.txt' title='Random Password Generator'>function&#8217;s source code</a><br />
<span id="more-90"></span><br />
There are plenty of ways to do this.  The simplest method would be to take a random number, generate an md5 hash, and then use the first 8 characters as the password.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">time</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: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>But this doesn&#8217;t guarantee you an even mix of upper case letters, lower case letters, and numbers.  To do that, we&#8217;ll need to use a few simple php functions and build a short script.</p>
<h5>Build a Loop to Create Eight Characters</h5>
<p>We&#8217;ll start our script by creating a blank string, looping eight times, and entering a character in the string each time.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$password</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'a'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This creates a blank string ($password) and iterates a loop eight times.  At this point, the loop simply enters the letter &#8216;a&#8217; into $password &#8211; so you end output should be &#8216;aaaaaaaa.&#8217;</p>
<h5>Generate Random Characters</h5>
<p>Now we need to generate random characters to go inside of the string.  To do this, we can make use of the rand() and chr() functions.  Replace the loop contents with this line.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">95</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>chr() takes an integer and returns the ASCII equivalent of that number.  In this case, we&#8217;re using rand() to get a number between 60 and 95 &#8211; so we should get an uppercase letter in return.  Our random password should now contain eight random upper-case letters.</p>
<h5>Randomly Enter Uppercase, Lowercase, and Numbers</h5>
<p>To make the random password more secure, we should randomize whether the new character is a number, an upper-case letter, or a lower-case letter.  We can execute a simple &#8220;switch&#8221; statement to randomly choose which type of character to enter.</p>
<p>Replace the loop contents with this new snippet.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//  Add a random digit, 0-9</span>
   <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
   <span style="color: #000088;">$password</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//  Add a random upper-case letter</span>
   <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
   <span style="color: #000088;">$password</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">65</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">//  Add a random lower-case letter</span>
   <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span>
   <span style="color: #000088;">$password</span>  <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">97</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">122</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>We&#8217;re using rand(1, 3) to randomly choose which case to execute.  Each case then enters a different type of character in the string.  The first case simply returns a random digit.  The second and third cases use chr() and rand() to return a random character.</p>
<p>At this point, the script should give you an eight-character password with a random mix of uppercase letters, lowercase letters, and numbers.  Now you can e-mail the password to the user, take a hash of the password, and store it in the database.</p>
<p>For reference, here&#8217;s the entire script placed in a function.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> randPassword<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$x</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;=</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">;</span> <span style="color: #000088;">$x</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">//  Add a random digit, 0-9</span>
      <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>
      <span style="color: #000088;">$password</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">//  Add a random upper-case letter</span>
      <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">:</span>
      <span style="color: #000088;">$password</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">65</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">//  Add a random lower-case letter</span>
      <span style="color: #b1b100;">case</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span>
      <span style="color: #000088;">$password</span>  <span style="color: #339933;">.=</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">97</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">122</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$password</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/01/random-password/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>How to Pass All Elements of a Form to the End in a Multi-Page Form</title>
		<link>http://www.earn-web-cash.com/2008/01/27/multi-page-form/</link>
		<comments>http://www.earn-web-cash.com/2008/01/27/multi-page-form/#comments</comments>
		<pubDate>Sun, 27 Jan 2008 22:44:29 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[snippet]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/01/27/how-to-pass-all-elements-of-a-form-to-the-end-in-a-multi-page-form/</guid>
		<description><![CDATA[Sometimes forms get long, unsightly, and intimidating.  It'd be great if you could cut them up into three or four parts - with a few fields on each page.

In order to do that, you need to figure out some way of storing or passing along the information from the first pages.  I've heard a bunch of crazy ideas - from storing the information in session variables to writing each part to the database.

The easiest thing to do is attach a <em>very</em> brief php function to the bottom of each page.  It'll do all the work for you and continue to post every item the user has entered.]]></description>
			<content:encoded><![CDATA[<p>Sometimes forms get long, unsightly, and intimidating.  It&#8217;d be great if you could cut them up into three or four parts &#8211; with a few fields on each page.</p>
<p>In order to do that, you need to figure out some way of storing or passing along the information from the first pages.  I&#8217;ve heard a bunch of crazy ideas &#8211; from storing the information in session variables to writing each part to the database.</p>
<p>The easiest thing to do is attach a <em>very</em> brief php function to the bottom of each page.  It&#8217;ll do all the work for you and continue to post every item the user has entered.<span id="more-77"></span></p>
<p>To start with, let&#8217;s create a hypothetical page one of a form.  This will give us something to work with for the rest of this tutorial.</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;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;script.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</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;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;firstname&quot;</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;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;lastname&quot;</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;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;poneSubmit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Continue&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;">form</span>&gt;</span></pre></div></div>

<p>Here we&#8217;ve got three form elements &#8211; although only two of them really count.  When we get to the second page, we need to make sure that &#8220;firstname&#8221; and &#8220;lastname&#8221; are passed along so that the final processing page can store the data appropriately.</p>
<p>When the second page (&#8220;script.php&#8221;) loads, these values will be stored in <code>$_POST['firstname']</code> and <code>$_POST['secondname']</code>.</p>
<p>Every value in a form that is submitted with <code>method="post"</code> ends up in the superglobal array <code>$_POST</code> with a key equal to its <code>name</code> attribute in the form.</p>
<p>In order to continue to pass these values along and make them accessible through the <code>$_POST</code> superglobal on other pages, we can use a simple foreach loop.  With each iteration of the loop, we&#8217;ll create a new <code>&lt;input type="hidden" /&gt;</code> to store the information.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;input type=&quot;hidden&quot; name=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> 
    <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$val</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; /&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This will cycle through the <code>$_POST</code> array and create all of the hidden elements for us.  So we&#8217;d end up with this being added to our next page in the form.</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;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'hidden'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'firstname'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Bob'</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;">'hidden'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'lastname'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Stevenson'</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;">'hidden'</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'poneSubmit'</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Continue'</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div>

<p>All you need to do is add that snippet of php to the end of your form on each subsequent(after page one), and all of the values will end up in the <code>$_POST</code> array at the end.  [Note:  Make sure this is <strong>inside</strong> the form tags, or else it won't get passed along.]</p>
<p>If you want to take it one step further, you can standardize this into a neat little function.  Then include this function in your common includes file, and you can use it on any page with a simple function call.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> passArray<span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;input type=&quot;hidden&quot; name=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> 
      <span style="color: #0000ff;">'&quot; value=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$val</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; /&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s all there is to it!  Go write up some forms.</p>
<p>[Note:  If you're wondering why the <code>"\r\n"</code> is there, it's just to make the source code look nicer.  It adds a newline so that your source code is nice and spread out.  Otherwise, every element our function adds would be on the same line - making the source code pretty illegible.]</p>
<p><strong>Update.</strong>  It&#8217;s been pointed out to me that there&#8217;s a possible security hole in this method.  No big deal.  This article that revisits <a href="http://www.earn-web-cash.com/2008/02/08/multi-page-form-revisted/">multi-page forms</a> patches the hole up nice and snug.  I&#8217;d suggest you take a look at it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/01/27/multi-page-form/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
	</channel>
</rss>

