<?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>JJ Is Me &#187; class</title>
	<atom:link href="http://jjis.me/a/tag/class/feed" rel="self" type="application/rss+xml" />
	<link>http://jjis.me</link>
	<description>Me And My Code</description>
	<lastBuildDate>Sun, 29 Jan 2012 22:14:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Database PHP Class</title>
		<link>http://jjis.me/a/253</link>
		<comments>http://jjis.me/a/253#comments</comments>
		<pubDate>Tue, 15 Jun 2010 17:38:25 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=253</guid>
		<description><![CDATA[I&#8217;m back with another chunk of code. This time, it&#8217;s my database class. I got sick of coming across classes that didn&#8217;t have everything I needed, or didn&#8217;t do it correctly. One of my biggest problems was an inability to nest query calls within another query result&#8217;s output. Example: With this class, that is not [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back with another chunk of code.  This time, it&#8217;s my database class.</p>
<p>I got sick of coming across classes that didn&#8217;t have everything I needed, or didn&#8217;t do it correctly.  One of my biggest problems was an inability to nest query calls within another query result&#8217;s output.</p>
<p><span id="more-253"></span></p>
<h2>Example:</h2>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php

// main query
// gets a list of companies from the companies table
$a = &quot;SELECT id, company_name FROM companies&quot;;
$a = $db-&gt;query($a);

while  ($aa = $db-&gt;fetch_object($a) ) :

     echo '&lt;div class=&quot;company_name&quot;&gt;' . $aa-&gt;company_name . '&lt;/div&gt;';

     // get the contacts for each company
     $b = &quot;SELECT contact_name, phone1 FROM contacts WHERE company_id = $aa-&gt;id&quot;; // because we've already used $a, we can't use it again during $a's output
     $b = $db-&gt;query($b);

     // output all contacts for the each company
     while ( $bb = $db-&gt;fetch_object($b) ) : // the same thing as $a, we can not use $aa again during its output
          echo '&lt;div class=&quot;contact_name&quot;&gt;' . $bb-&gt;contact_name . '&lt;/div&gt;';
          echo '&lt;div class=&quot;contact_phone&quot;&gt;' . $bb-&gt;phone1 . '&lt;/div&gt;';
     endwhile;

endwhile;

?&gt;
</pre>
<p>With this class, that is not a problem. The only requirement is that you can&#8217;t name your $sql and $results ($row) variables the same (noted in the code above). Other than that, there&#8217;s nothing to it. It&#8217;s just a way to provide clean, and efficient database interaction.</p>
<h2>Database.Core.php Code</h2>
<ul>
<li>
<p><strong>Updated 06-23-2010: </strong></p>
<ul>
<li>Renamed main database class file to Database.Core.php</li>
<li>Removed the $connection settings and placed them in the Database.Connect.Config.php file. Helps keep hands out of the core file.</li>
<li><strong>show_mysql_error(): </strong>edited so it only receives and passes the original SQL statement, to the error_backtrace() method, upon error.</li>
<li><strong>query(): </strong> no longer fires the die() function and close_db() method. Send the erroring SQL statement to show_mysql_error() method for handling of error output.</li>
<li><strong>multi_query(): </strong> no longer fires the die() function and close_db() method. Send the erroring SQL statement to show_mysql_error() method for handling of error output.</li>
<li><strong>error_backtrace(): </strong>replaced previous method with cleaner code. The error now has formattting for easier readability.</li>
</ul>
</li>
</ul>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">

&lt;?php
/* **********************************************************************
*
* 	DB connection variables
*	Must be set in order to establish a connection to the database
*
********************************************************************** */

$connection = (object) array();
require ( 'Database.Connect.Config.php' );

/* **********************************************************************
* END :::
********************************************************************** */

/* **********************************************************************
*	DatabaseFunctions is a class created to manage database functions
*
*	The class manages all database interraction for purpose of allowing certain things to be
*	turned on and off.  An example would be Error Reporting.  Once the application is on the live
*	server, we can set $config-&gt;ShowErrors to false and error reporting for database erros will no
*	be shown.
*
*	This is real simply to use
*
*	Examples:
*
**********
*
*		Get number of rows returned in a query (you can also nest this:
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;; // would return 4 rows
*			$sql = $db-&gt;fetch_object($sql);
*			$rows = $db-&gt;num_rows();
*			echo $rows; // 4
*
*		Nested num_rows();
*			$a = &quot;SELECT fieldA FROM tableA&quot;; // would return 2 rows
*			$a = $db-&gt;fetch_object($a);
*			$a_rows = $db-&gt;num_rows();
*			echo $a_rows; // 2
*
*			while ($aa = $db-&gt;fetch_object($a) ) :
*				$b = &quot;SELECT fieldA FROM tableA&quot;; // would return 6 rows
*				$b = $db-&gt;fetch_object($b);
*				$b_rows = $db-&gt;num_rows();
*					echo $b_rows; // 6
*			endwhile;
*
*
**********
*
*
*		Results as Object:
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
*			$sql = $db-&gt;fetch_object($sql);
*
*			while ($row = $db-&gt;fetch_object($sql) ) :
*				echo $row-&gt;fieldA . ': ' . $row-&gt;fieldB;
*			endwhile;
*
*
**********
*
*
*		Results as Array:
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
*			$sql = $db-&gt;fetch_object($sql);
*
*			while ($row = $db-&gt;fetch_array($sql) ) :
*				echo $row['fieldA'] . ': ' . $row['fieldB'];
*			endwhile;
*
*
**********
*
*
*		Return value of a row or field in a row ( uses the rather inefficient mysql_fetch_row() )
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
*			$val = $db-&gt;fetch_row(1);        // would return fieldB's value
*				-- OR --
*			$val = $db-&gt;fetch_row('fieldA'); // would obviously return fieldA's value
*
*
**********
*
*
*		Return value of a query more efficiently (avoids the inefficient mysql_fetch_row() function)
*			$sql = &quot;SELECT fieldA FROM tableA&quot;;
*			$fieldA = $db-&gt;fetch_value($sql); // would return fieldA's value
*
*
**********
*
*
*		 Return the query result set as an array:
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;; // returns 4 rows
*			$results = $db-&gt;to_array($sql);
*
*			$results[0]['fieldA'] = 'valueA 1';
*			$results[0]['fieldB'] = 'valueB 1';
*
*			$results[1]['fieldA'] = 'valueA 2';
*			$results[1]['fieldB'] = 'valueB 2';
*
*			$results[2]['fieldA'] = 'valueA 3';
*			$results[2]['fieldB'] = 'valueB 3';
*
*			$results[3]['fieldA'] = 'valueA 4';
*			$results[3]['fieldB'] = 'valueB 4';
*
*
********************************************************************** */

class System_Database {

	# set whether errors should be displayed or not
	# probably want to turn off once site is live
	var $displayErrors = false;

	/* ****************************************************************
	*
	* Establish connection to the database
	* Be sure to set the connection info above
	*
	**************************************************************** */
	function connect() {
		global $connection;
		$connection-&gt;mysqlLink = mysql_connect($connection-&gt;host, $connection-&gt;user, $connection-&gt;password);

		# The connection failed for some reason
		if ( !isset($connection-&gt;mysqlLink) ) :
			die(&quot;Error connecting to the server&quot;);

		# The connection is good so lets get the Application Config Settings
		# and create the $config object
		elseif ( isset($connection-&gt;mysqlLink) ) :
			$db_selected = mysql_select_db($connection-&gt;db);

		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Run the query
	*
	**************************************************************** */
	function sqlId() {
		$id = rand();
		$uniqueId[] = 'sql' . $id;
		$uniqueId[] = 'row' . $id;
		return $uniqueId;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* If $showErrors is set to true or $config-&gt;ShowErrors
	* is set and is true display the error that has occurred
	*
	**************************************************************** */
	function show_mysql_error( $sql ) {
		$this-&gt;error_backtrace( $sql );
		die();
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Run the query
	*
	**************************************************************** */
	function query( $sql ) {
		$this-&gt;result=mysql_query( $sql );
		if ( !$this-&gt;result ) :

			$this-&gt;show_mysql_error( $sql );

		else :

			return $this-&gt;result;

		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Connect to the server using the mysqli extension
	* This is used automatically during multi_query()
	*
	**************************************************************** */
	function mySqliConnect() {
		global $connection;
		$connection-&gt;mySqli = new mysqli($connection-&gt;host, $connection-&gt;user,  $connection-&gt;password, $connection-&gt;db);
		return $connection-&gt;mySqli;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Close the mysqli connection once we have finished
	* using the multi_query() method
	*
	**************************************************************** */
	function mySqliClose() {
		global $connection;
		mysqli_close($connection-&gt;mySqli);
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Execture the multi-query
	*
	**************************************************************** */
	function multi_query( $sql ) {

		$mysqli = $this-&gt;mySqliConnect();

		$this-&gt;result=mysqli_multi_query( $mysqli, $sql );

		if ( !$this-&gt;result ) :
			$this-&gt;show_mysql_error( $sql );
		else :
			$this-&gt;mySqliClose();
			return $this-&gt;result;
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the results of the query as an object
	*
	* Example:
	*	$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
	*	$sql = $db-&gt;fetch_object($sql);
	*
	*	while ($row = $db-&gt;fetch_object($sql) ) :
	*		echo $row-&gt;fieldA . ': ' . $row-&gt;fieldB;
	*	endwhile;
	*
	**************************************************************** */
	function fetch_object( $sql ) {
		$uniqueIdentifier=rand();
		$$uniqueIdentifier=mysql_fetch_object( $sql );
		return $$uniqueIdentifier;
		unset( $$uniqueIdentifier );
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the results of the query as an array
	*
	* Example:
	*	$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
	*	$sql = $db-&gt;fetch_object($sql);
	*
	*	while ($row = $db-&gt;fetch_object($sql) ) :
	*		echo $row['fieldA'] . ': ' . $row['fieldB'];
	*	endwhile;
	*
	**************************************************************** */
	function fetch_array( $sql ) {
		$uniqueIdentifier=rand();
		$$uniqueIdentifier=mysql_fetch_array( $sql );
		return $$uniqueIdentifier;
		unset( $$uniqueIdentifier );
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the number of rows returned in a query
	*
	**************************************************************** */
	function num_rows($result='') {
		$uniqueIdentifier=rand();
		if (empty($result)) $result = $this-&gt;result;
		$$uniqueIdentifier=mysql_num_rows( $result );
		return $$uniqueIdentifier;
		unset( $$uniqueIdentifier );
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the number of rows affected by a query
	*
	**************************************************************** */
	function rows_affected($result='') {
		$uniqueIdentifier=rand();
		if (empty($result)) $result = $this-&gt;result;
		$$uniqueIdentifier = mysql_rows_affected( $result );
		return $$uniqueIdentifier;
		unset( $$uniqueIdentifier );
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Runs the mysql_result() function, but a little differently
	*
	* if $this-&gt;fetch_row(1), it will return the second field
	* of the first row
	*
	* if $this-&gt;fetch_row('field_name'), it will return the value
	* for 'field_name' in the first row
	*
	**************************************************************** */
	function fetch_row ( $fieldName ) {
		if (is_numeric( $fieldName )) {
			$fieldValue=mysql_result( $this-&gt;result, $fieldName );
		} else {
			$fieldValue=mysql_result( $this-&gt;result, 0, $fieldName );
		}
		return $fieldValue;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the value of the specified field, in the specified
	* row.
	*
	* If no field or row is specified, it will default to first
	* row, first field
	*
	**************************************************************** */
	function fetch_value ( $sql='', $fieldName='', $row='' ) {
		$i=0;
		$fieldValue = false;

		if (empty($fieldName)) { $fieldName = 0; }
		if (empty($row)) { $row = 0; }
		$ret = array();
		$sql = $this-&gt;query($sql);
		if ($this-&gt;num_rows() &gt; 0) {
			while ($rec = mysql_fetch_array( $sql )) {
				for ($a=0; $a &lt; count($rec); $a++) {
					$ret[$i] = $rec;
				}
				$i++;
			}

			$fieldValue=$ret[$row][$fieldName];
		}

		return ($fieldValue);
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Returns the results of the query as an array
	*
	* Example:
	*	$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;; // returns 4 rows
	*	$results = $db-&gt;to_array($sql);
	*
	*	$results[0]['fieldA'] = 'valueA 1';
	*	$results[0]['fieldB'] = 'valueB 1';
	*
	*	$results[1]['fieldA'] = 'valueA 2';
	*	$results[1]['fieldB'] = 'valueB 2';
	*
	*	$results[2]['fieldA'] = 'valueA 3';
	*	$results[2]['fieldB'] = 'valueB 3';
	*
	*	$results[3]['fieldA'] = 'valueA 4';
	*	$results[3]['fieldB'] = 'valueB 4';
	*
	**************************************************************** */
	function to_array ( $sql='' ) {
		$i=0;
		$ret = array();
		$sql = $this-&gt;query($sql);
		while ($row = mysql_fetch_assoc( $sql )) {
			for ($a=0; $a &lt; count($row); $a++) {
				$ret[$i] = $row;
			}
			$i++;
		}
		return ($ret);
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* closes the database connection
	*
	* PHP nowadays does a really good job of trashing these connection
	* automatically. However, just to be safe, I typically call this
	* method in an include that is loaded after everything else
	*
	**************************************************************** */
	function close_db() {
		global $connection;
		if ($connection-&gt;mysqlLink) :
			mysql_close( $connection-&gt;mysqlLink );
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Will format system errors and display them
	*
	**************************************************************** */
	function error_backtrace( $sql ) {

		$errorsThrown = debug_backtrace();
		$errorThrown = $errorsThrown[2];

		echo &quot;
		&lt;style&gt;
			#error-container { width: 100%; color: #333!important; position: relative; background-color: #f3f3f3; border-bottom: 1px dotted #333; }
			#error-wrapper { font: 110%/0.8em arial!important; letter-spacing: 0.02em; width: 850px!important; background-color: #f3f3f3!important; padding: 10px!important; }
			#error-wrapper a { color: #cc6600; }
			#primary-error td { color: #333!important; padding: 4px!important; border: 1px solid #f3f3f3!important; }
			#primary-error td.left {
				width: 120px;
				text-align: right;
				padding: 8px 4px 8px 8px!important;
				margin: 0 8px 1px 0!important;
				background-color: #d3d3d3!important;
			}
			#error-wrapper p { text-align: left; padding: 18px; clear: both!important; }

			#previous-errors th { color: #333!important; padding: 6px; }
			#previous-errors td { color: #333!important; padding: 4px; border-top: 1px solid #666; border-right: 1px solid #666; }
		&lt;/style&gt;
		&quot;;

		echo &quot;&lt;div id=\&quot;error-container\&quot;&gt;&quot;
			. &quot;&lt;div id=\&quot;error-wrapper\&quot;&gt;&quot;
			. &quot;&lt;table id=\&quot;primary-error\&quot;&gt;\n&quot;
			. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;Error: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;Database error&lt;/td&gt;&lt;/tr&gt;\n&quot;
			. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;SQL: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot; . $sql . &quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;
			. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;MySQL Error: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot; . mysql_error() . &quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;
			. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;Calling Function: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot; . $errorThrown['function'] . &quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;
			. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;File Name: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot;.$errorThrown['file'].&quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;
			. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;On line: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot;.$errorThrown['line'].&quot;&lt;/td&gt;&lt;/tr&gt;\n&lt;/table&gt;\n&quot;
			. '&lt;p&gt;&amp;nbsp;&lt;/p&gt;'
			. '&lt;/div&gt;&lt;/div&gt;';
	}
	/* ****************************************************************
	* END :::
	**************************************************************** */

}
/* *********************************************************************************
* END :::
********************************************************************************* */

$db = new System_Database;
?&gt;
</pre>
<h2>Database.Connect.Config.php Code</h2>
<p><em>used for establishing the connection information for your database. this file is automatically included in the Database.Core.php file. just drop it in the same folder and you&#8217;re good to go.</em></p>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">

&lt;?php
	$connection-&gt;host           = 'localhost';
	$connection-&gt;user           = 'user_name';
	$connection-&gt;password    = 'your_password';
	$connection-&gt;db             = 'your_database';
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/253/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>(UPDATED 08-10-2010) Forms Class for easy and consistant forms</title>
		<link>http://jjis.me/a/100</link>
		<comments>http://jjis.me/a/100#comments</comments>
		<pubDate>Wed, 31 Mar 2010 12:48:55 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=100</guid>
		<description><![CDATA[UPDATED 08-10-2010: I&#8217;ve cleaned up a lot of code and organized the code a little better. One major improvement is the passing of element attributes. You can now pass an unlimited number of attributes. If there are any you want omitted from the actual element tag, you can add it to the $attributes_not_allowed array. I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATED 08-10-2010:</strong></p>
<ul>
<li>I&#8217;ve cleaned up a lot of code and organized the code a little better.</li>
<li>One major improvement is the passing of element attributes. You can now pass an unlimited number of attributes. If there are any you want omitted from the actual element tag, you can add it to the $attributes_not_allowed array.</li>
<li>I&#8217;ve added notes everywhere and hopefully they will assist you. If you find any bugs, feel free to post in comments and will fix them ASAP</li>
</ul>
<p>As it states in the notes of the script, this is not for auto-generated forms. This is simply a means of developing forms with consistency. There are methods for parsing the $_POST array and injecting the $_POST variables and values in the $form object. It will auto-generate the variables given in a SQL statement inject those into the $form object. It will also insert a posted form into a specified database and table.</p>
<p>This is a continual work in progress as I create forms under different conditions. Check back as I will update the code as needed</p>
<p>If you have any problems or suggestions, leave comments.</p>
<p>You will see references to the a <a href="http://jjis.me/a/253">$db object</a> in the code below. Go to the <a href="http://jjis.me/a/253">Database PHP Class</a> to view the code.</p>
<p><span id="more-100"></span></p>
<h2>Primary Forms Class (Forms.Class.php)</h2>
<ul>
<li><strong>Edit 06-23-2010: </strong>Fixed an is_array evaluation error in the checkbox method.</li>
</ul>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php
/*
	Script Name: Forms
	Author: JJ Jiles
	Website: http://jjis.me
	Version: 1
	Copyright (C) March 31 2010

	This function allows an easy way to create consistent forms in your applications. It was not designed
	to be an auto form generator. It is designed for assistant in consistency.

	What it does:
		- Allows for consistent form generation from a programming standpoint
		- Automatically cycles through the $_POST array and creates $form objects accordingly
		- Creates an easy way to generate a form, have it submitted and inserted into specific DB and table
		- Takes a SQL statement, executes it, loops through and creates the $form objects according to the returned fields and values

	There are instructions above each function, but here are some sample uses:

	Radio/Checkbox:
			$options = array('class'=&gt;'some-class');
			$form-&gt;checkbox('field_name',array('Display Text'=&gt;'value','Display Text 2'=&gt;'value 2'), $options);
		Outputs:
			&lt;input type=&quot;checkbox&quot; name=&quot;field_name[]&quot; id=&quot;field_name0&quot; value=&quot;value&quot; class=&quot;checkbox&quot; /&gt;&lt;label for=&quot;field_name0&quot;&gt;Display Text&lt;/label&gt;
			&lt;input type=&quot;checkbox&quot; name=&quot;field_name[]&quot; id=&quot;field_name1&quot; value=&quot;value 2&quot; class=&quot;checkbox&quot; /&gt;&lt;label for=&quot;field_name1&quot;&gt;Display Text 2&lt;/label&gt;

	Input:
			$options = array('maxlength'=&gt;40, 'size'=&gt;25)
			$form-&gt;input('field_name', $options);
		Outputs:
			&lt;input type=&quot;text&quot; name=&quot;field_name&quot; id=&quot;field_name&quot; value=&quot;&quot; maxlength=&quot;40&quot; size=&quot;25&quot; class=&quot;input&quot; /&gt;

	Submit:
			$form-&gt;submit('submit-button', 'Submit);
			&lt;input type=&quot;submit&quot; name=&quot;submit-button&quot; id=&quot;submit-button&quot; value=&quot;Submit&quot; class=&quot;submit&quot; /&gt;
			$form-&gt;submit('redo', 'Clear Form');
			&lt;input type=&quot;submit&quot; name=&quot;redo&quot; id=&quot;redo&quot; value=&quot;Clear Form&quot; class=&quot;reset&quot; /&gt;

*/

/* ****************************************************************************
*
* START :::
*	THE Form class and methods
*
**************************************************************************** */
class Forms {

	/* ***
	* User Forms.Config.php to establish defaults for the following objects */
	var $required_indicator;
	var $excluded_indicator;
	var $email_template;
	var $classes;
	var $attributes_not_allowed;
	var $reserved;

	var $format;
	var $email='';
	var $error='';
	var $message='';

	var $input_name;
	var $input_value;
	var $options;
	var $value_exclude = false;
	var $method;		// $form-&gt;method-&gt;hasPosts()
	var $database;		// $form-&gt;database-&gt;insert()
	var $post;		// $form-&gt;post-&gt;referer();
	/* *** */

	function Forms() {
		require('Forms.Config.php');
		require('Forms.Method.Formatting.php');
		require('Forms.Method.Methods.php');
		require('Forms.Method.Database.php');
		require('Forms.Method.Post.php');

		#
		# establish the required/excluded indicators as specified by developer
		$this-&gt;reserved['column_type_indicators'] = array($this-&gt;required_indicator, $this-&gt;excluded_indicator);
		array_merge(array($this-&gt;required_indicator, $this-&gt;excluded_indicator, $this-&gt;reserved['replace_what']));
		array_merge($this-&gt;reserved['replace_with'], array('',''));

		$this-&gt;method 		= new Forms_Methods;
		$this-&gt;database 	= new Forms_DB;
		$this-&gt;format		= new Forms_Formatting;
		$this-&gt;post		= new Forms_Post;
	}

	/* **************************************************************************************************
	* START :::
	*   $options = array();
	*   $options['value'] = 'some value'; // whatever default you want
	*   $options['class'] = 'myClass // overrides the default &quot;input&quot; class
	*   $options['size'] = '65' // set $options['class']='' if you prefer to use &quot;size&quot;
	*
	*   $form-&gt;select('field_name', $options);
	*     -- OR --
	*   $form-&gt;select('field_name', array('value'=&gt;'some value','class'=&gt;'myClass');
	*
	*     // Will output:
	*     &lt;input type=&quot;text&quot; name=&quot;field_name&quot; id=&quot;field_name&quot; class=&quot;myClass&quot; value=&quot;some value&quot; /&gt;
	************************************************************************************************** */
	function input( $name, $options='' ) {
		global $app;
		$this-&gt;input_return = false;
		$this-&gt;input_name 	= $name;
		$this-&gt;options		= $options;
		$this-&gt;options		= $this-&gt;returnValue();

		$type = 'text';
		if (is_array($this-&gt;options) &amp;&amp; isset($this-&gt;options['type'])) :
			$type = $this-&gt;options['type'];
		endif;
		$this-&gt;options['type'] = $type;

		$input = &quot;&lt;input type=\&quot;{$type}\&quot; name=\&quot;{$name}\&quot; id=\&quot;{$name}\&quot;&quot;;
		$input .= $this-&gt;addOptions();
		$input .= &quot; /&gt;&quot;;

		if (@$this-&gt;input_return) {
			return $input;
		} else {
			echo $input;

		}
	}
	/* ***********************************************************
	  * END :::
	*********************************************************** */

			/* ***********************************************
			* START :::
			*   The following are types of inputs
			*   typically the only difference is the TYPE
			*********************************************** */

				# PASSWORD
				function password( $name, $options='') {
					$this-&gt;options			= $options;
					$this-&gt;options			= $this-&gt;returnValue();
					$this-&gt;options['type'] 	= 'password';					

					return $this-&gt;input($name,$this-&gt;options);
				}

				# FILE
				function _file( $name, $options='') {
					$this-&gt;options 		= $options;
					$this-&gt;options			= $this-&gt;returnValue();
					$this-&gt;options['type'] 	= 'file';
					return $this-&gt;input($name,$this-&gt;options);
				}

				# HIDDEN
				function hidden( $name, $options='') {
					$this-&gt;options 		= $options;
					$this-&gt;options			= $this-&gt;returnValue();
					$this-&gt;options['type'] 	= 'hidden';
					return $this-&gt;input($name,$this-&gt;options);
				}

				# SUBMIT
				function submit( $name, $options='') {
					$this-&gt;options 		= $options;
					$this-&gt;options			= $this-&gt;returnValue();
					$this-&gt;options['type'] 	= 'submit';
					return $this-&gt;input($name,$this-&gt;options);
				}

				# RESEST
				function reset( $name, $options='') {
					$this-&gt;options 		= $options;
					$this-&gt;options			= $this-&gt;returnValue();
					$this-&gt;options['type'] 	='reset';
					return $this-&gt;input($name,$this-&gt;options);
				}

				# BUTTON
				function button( $name, $options='' ) {
					$this-&gt;options 		= $options;
					$this-&gt;options			= $this-&gt;returnValue();
					$this-&gt;options['type'] 	='button';
					return $this-&gt;input($name,$this-&gt;options);
				}

				# IMAGE
				function image( $name, $options='' ) {
					$this-&gt;options 		= $options;
					$this-&gt;options			= $this-&gt;returnValue();
					$this-&gt;options['type'] 	='image';
					return $this-&gt;input($name,$this-&gt;options);
				}
			/* ***********************************************
			*	END $form-&gt;input method
			*********************************************** */

	/* **************************************************************************************************
	  * END :::
	************************************************************************************************** */

	/* ****************************************************************************************
	* START :::
	* 	See Input directions above
	**************************************************************************************** */
	function textarea( $name, $options='' ) {

		$this-&gt;input_return 	= false;
		$this-&gt;options 		= $options;
		$this-&gt;input_name 		= $name;
		$this-&gt;options 		= $this-&gt;returnValue();
		$this-&gt;options['type'] 	= 'textarea';

		$input = '&lt;textarea name=&quot;'.$name.'&quot; id=&quot;'.$name.'&quot;'
				. $this-&gt;addOptions($value_exclude=true)
				. '&gt;'
				. $this-&gt;input_value
				. '&lt;/textarea&gt;';

		if (@$this-&gt;input_return) {
			return $input;
		} else {
			echo $input;
		}
	}
	/* ****************************************************************************************
	* END :::
	**************************************************************************************** */

	/* ****************************************************************************************
	*
	*	$selectArray = array();
	*	$selectArray['Display Label'] = &quot;some value&quot;;
	*	$selectArray['Display Label 2'] = &quot;some value 2&quot;;
	*
	*	$options = array();
	*	$options['default'] = 'some value'; // should be the value of the checkbox you want checked by default
	*	$options['return'] = false; // default - if set to true, the results will not be echoed
	*
	*	$form-&gt;select('field_name', $selectArray, $options);
	*		-- OR --
	*	$form-&gt;select('field_name', array('Display Label'=&gt;'some value','Display Label 2'=&gt;'some value 2'), array('default'=&gt;some value'));
	*
	*	// Will output:
	*		&lt;select name=&quot;field_name&quot; id=&quot;field_name&quot; class=&quot;input&quot;&gt;&lt;option value=&quot;&quot;&gt;&lt;/option&gt;&lt;option value=&quot;some value&quot; selected&gt;Display Label&lt;/option&gt;&lt;option value=&quot;some value 2&quot; &gt;Display Label 2&lt;/option&gt;&lt;/select&gt;
	*
	**************************************************************************************** */
	function select( $name, $values, $options='' ) {
		global $app;
		$this-&gt;input_return 	= false;
		$this-&gt;input_name 		= $name;
		$this-&gt;options			= $options;
		$this-&gt;options			= $this-&gt;returnValue();
		$this-&gt;values			= $values;
		$this-&gt;options['type'] 	= 'select';

		$this-&gt;options['default'] = isset($this-&gt;options['default'])?$this-&gt;options['default']:'';

		# php requires [] trailing the input name if you want the values
		# considered an array. we strip the brackets for evaluation only
		$post_value='';
		$post_name = str_replace('[]','',$name);

		$selectField = '&lt;select name=&quot;'.$name.'&quot; id=&quot;'.$name.'&quot;'
					. $this-&gt;addOptions($value_exclude=true)
					. '&gt;';

		$selectOptions = (isset($this-&gt;options['multiple'])) ? '' : '&lt;option value=&quot;&quot;&gt;&lt;/option&gt;';

		if (!empty($this-&gt;values)) {
			foreach ($this-&gt;values as $item) :
				$count=1; $value=''; $text='';

				if (is_array($item)) {
					foreach ($item as $key=&gt;$val) :
						$value 	= ($count==1)?$val:$value;
						$text 	= ($count==2)?$val:$text;
						$count++;
					endforeach;
				} else {
					$value 	= $item;
					$text 	= $item;
				}

				# determine if the current select option should be selected
				$selected = ( $this-&gt;options['default'] == $value &amp;&amp; empty($selected)) ? ' selected' : ''; // non-array eval
				$selected = ( $this-&gt;selectValue($this-&gt;input_value,$value) ) ? ' selected' : $selected; // array eval

				# append the &lt;option&gt; to $selectOptions
				$selectOptions .= '&lt;option value=&quot;'.$value.'&quot;'.$selected.'&gt;'.$text.'&lt;/option&gt;';
				$s = (!empty($selected))?false:'selected';

			endforeach;
		}

		$selectField .= $selectOptions;
		$selectField .= '&lt;/select&gt;';

		if (@$s) :
			$selectField = str_replace('%%selected%%',$s,$selectField);
		endif;

		if (@$this-&gt;input_return) {
			return $selectField;
		} else {
			echo $selectField;
		}
	}

		/* **********************************************
		* 	Used to determine if the value is selected
		*	in the SELECT element
		********************************************** */
		function selectValue($list,$value) {
			if ($value == $list || (is_array($list) &amp;&amp; in_array($value,$list)) ) {
				return true;
			} else {
				return false;
			}
		}
		/* **********************************************
		* END :::
		********************************************** */

	/* ****************************************************************************************
	* END :::
	**************************************************************************************** */

			/* **********************************************************************
			* START :::
			* Creates a SELECT element containing US states
			*	Create a table called `state_list` with fields
			* 	`state`,`state_long`
			*
			*	CREATE TABLE `state_list` (
			*		`state` char(2) NOT NULL DEFAULT '',
			*		`state_long` varchar(100) NOT NULL DEFAULT '',
			*		PRIMARY KEY (`state`)
			*	) ENGINE=MyISAM DEFAULT CHARSET=latin1;
			*
			* Beyond that, it follows the same rules as the SELECT function above
			********************************************************************** */
			function state_select($name, $options='') {
				global $db, $config;

				$option_text = isset($options['short'])?'state':'state_long';

				$sql = &quot;SELECT state, {$option_text} as state_text FROM state_list ORDER BY state_long ASC&quot;;
				$states = $db-&gt;to_array($sql);

				$return = (isset($options['return']) &amp;&amp; $options['return'] === true)?true:false;
				$options['return']=true;
				$states = $this-&gt;select($name, $states, $options);

				if (@$return) {
					return $states;
				} else {
					echo $states;
				}
			}
			/* **********************************************************************
			  * END :::
			********************************************************************** */

	/* ****************************************************************************************
	*	$radioArray = array();
	*	$radioArray['Display Label'] = &quot;some value&quot;;
	*	$radioArray['Display Label 2'] = &quot;some value 2&quot;;
	*
	*	$options = array();
	*	$options['br'] = '&lt;br /&gt;' // exclusion will create inline elements
	*	$options['default'] = 'some value'; // should be the value of the checkbox you want checked by default
	*	$options['return'] = false; // default - if set to true, the results will not be echoed
	*
	*	$form-&gt;radio('field_name', $radioArray, $options);
	*		-- OR --
	*	$form-&gt;radio('field_name', array('Display Label'=&gt;'some value','Display Label 2'=&gt;'some value 2'), array('br'=&gt;'&lt;br /&gt;','default'=&gt;'some value'));
	*
	*	// Will outpu:
	*		&lt;input type=&quot;radio&quot; name=&quot;field_name&quot; id=&quot;field_name&quot; class=&quot;radio&quot; value=&quot;some value&quot; checked /&gt;&lt;label&gt;Dsiplay Label&lt;/label&gt;&lt;br /&gt;
	*		&lt;input type=&quot;radio&quot; name=&quot;field_name&quot; id=&quot;field_name&quot; class=&quot;radio&quot; value=&quot;some value 2&quot; /&gt;&lt;label&gt;Dsiplay Label 2&lt;/label&gt;&lt;br /&gt;
	*
	**************************************************************************************** */
	function radio( $name, $values=&quot;&quot;, $options=&quot;&quot; ) {
		global $app;
		$this-&gt;input_return 		= false;
		$this-&gt;input_name 			= $name;
		$this-&gt;options				= $options;
		$this-&gt;options				= $this-&gt;returnValue();
		$this-&gt;values				= $values;

		$posted_values				= ( isset($_POST[$name]) ) ? $_POST[$name] : -1;

		# establish some defaults
		$this-&gt;options['type'] 		= 'radio';
		$this-&gt;options['default']	= isset($this-&gt;options['default'])?$this-&gt;options['default']:-1;
		$this-&gt;options['class'] 		= isset($this-&gt;options['class'])?$this-&gt;options['class']:$this-&gt;options['type'];
		$this-&gt;options['checked']	= isset($this-&gt;options['checked'])?$this-&gt;options['checked']:'';
		$this-&gt;options['br'] 		= isset($this-&gt;options['br'])?$this-&gt;options['br']:'';
		$this-&gt;options['is_array'] 	= isset($this-&gt;options['is_array'])?$this-&gt;options['is_array']:false;

		$input='';
		if (!empty($values)) {
			$counter=0;

			if ( @strchr($name,'[]') ) :
				$name = str_replace('[]','',$name);
				$this-&gt;input_name = $name;
				$this-&gt;options['is_array'] = true;
			endif;

			$array_name = (@$this-&gt;options['is_array'])?'[]':'';
			$single     = ( count($values) == 1 ) ? true : false;

			foreach ($values as $key=&gt;$val) {

				// the selected radio is specified by number in array count
				$checked = ( $counter == $this-&gt;options['default'] ) ? ' checked' : '';
				// form's posted. see if this radio is selected
				$checked = ( !is_array( $posted_values ) &amp;&amp; $val == $posted_values ) ? ' checked' : $checked;
				// a single instance of a radio
				$checked = ( @$this-&gt;options['checked'] ) ? ' checked' : $checked;

				if ((
					isset($this-&gt;$name)
					&amp;&amp; ( !empty($this-&gt;$name) || $this-&gt;$name == 'Y' ) )
				    	&amp;&amp; @$single ) :
						$checked = ' checked';
				endif;

				$input .= &quot;&lt;input type=\&quot;radio\&quot; &quot;
						. &quot;name=\&quot;{$name}{$array_name}\&quot; id=\&quot;{$name}{$val}\&quot; &quot;
						. &quot;value=\&quot;{$val}\&quot;&quot;
						. $this-&gt;addOptions($value_excluded=true)
						. $checked
						. &quot; /&gt;\n&quot;
						. &quot;&lt;label for=\&quot;{$name}{$val}\&quot;&gt;{$key}&lt;/label&gt;&quot; . $this-&gt;options['br'] . &quot;\n&quot;;
				$counter++;
			}
		}

		if (@$this-&gt;input_return) {
			return $input;
		} else {
			echo $input;
		}
	}
	/* ****************************************************************************************
	  * END :::
	**************************************************************************************** */

	/* ****************************************************************************************
	*
	*	$checkboxArray = array();
	*	$checkboxArray['Display Label'] = &quot;some value&quot;;
	*	$checkboxArray['Display Label 2'] = &quot;some value 2&quot;;
	*
	*	$options = array();
	*	$options['br'] = '&lt;br /&gt;' // exclusion will create inline elements
	*	$options['default'] = 'some value'; // should be the value of the checkbox you want checked by default
	*	$options['return'] = false; // default - if set to true, the results will not be echoed
	*
	*	$form-&gt;checkbox('field_name', $checkArray, $options);
	*		-- OR --
	*	$form-&gt;checkbox('field_name', array('Display Label'=&gt;'some value','Display Label 2'=&gt;'some value 2'), array('br'=&gt;'&lt;br /&gt;','default'=&gt;'some value'));
	*
	*	// Will outpu:
	*		&lt;input type=&quot;checkbox&quot; name=&quot;field_name[]&quot; id=&quot;field_name&quot; class=&quot;checkbox&quot; value=&quot;some value&quot; checked /&gt;&lt;label&gt;Dsiplay Label&lt;/label&gt;&lt;br /&gt;
	*		&lt;input type=&quot;checkbox&quot; name=&quot;field_name[]&quot; id=&quot;field_name&quot; class=&quot;checkbox&quot; value=&quot;some value 2&quot; /&gt;&lt;label&gt;Dsiplay Label 2&lt;/label&gt;&lt;br /&gt;
	*
	**************************************************************************************** */
	function checkbox( $name, $values=&quot;&quot;, $options=&quot;&quot; ) {
		global $app;
		$this-&gt;input_return 		= false;
		$this-&gt;input_name 			= $name;
		$this-&gt;options				= $options;
		$this-&gt;options				= $this-&gt;returnValue();
		$this-&gt;values				= $values;

		# establish some defaults
		$this-&gt;options['type'] 		= 'checkbox';
		$this-&gt;options['default']	= isset($this-&gt;options['default'])?$this-&gt;options['default']:-1;
		$this-&gt;options['class'] 		= isset($this-&gt;options['class'])?$this-&gt;options['class']:$this-&gt;options['type'];
		$this-&gt;options['checked']	= isset($this-&gt;options['checked'])?$this-&gt;options['checked']:'';
		$this-&gt;options['br'] 		= isset($this-&gt;options['br'])?$this-&gt;options['br']:'';
		$this-&gt;options['is_array'] 	= isset($this-&gt;options['is_array'])?$this-&gt;options['is_array']:false;

		$input='';
		if (!empty($values)) {
			$counter=0;

			$name_is_array = (bool) strchr($name,'[]');
			$this-&gt;options['is_array'] = ( !$name_is_array ) ? $this-&gt;options['is_array'] : true;

			$array_name = '';

			if ( @$this-&gt;options['is_array'] ) :

				$name = str_replace('[]','',$name);
				$this-&gt;input_name = $name;
				$array_name = '[]';

			endif;

			$posted_values  = array();
			$no_post        = true;

			if ( @$this-&gt;method-&gt;hasPost() ) :
				$posted_values = isset( $_POST[$this-&gt;input_name] ) ? $_POST[$this-&gt;input_name] : $posted_values;
				$no_post       = false;

			endif;

			$single = ( count($values) == 1 ) ? true : false;

			foreach ($values as $key=&gt;$val) {
				// the checked box is specified by number in array count
				$checked = ( $counter == $this-&gt;options['default'] &amp;&amp; @$no_post ) ? ' checked' : '';
				// form's posted. see if this checkbox is checked
				$checked = ( @$this-&gt;options['is_array'] &amp;&amp; in_array($val, $posted_values)) ? ' checked' : $checked;
				// a single instance of a checkbox
				$checked = ( @$this-&gt;options['checked'] ) ? ' checked' : $checked;
				//
				$checked = ( isset($this-&gt;$name) &amp;&amp; $this-&gt;$name == $val ) ? ' checked' : $checked;

				$input .= &quot;&lt;input type=\&quot;checkbox\&quot; &quot;
						. &quot;name=\&quot;{$name}{$array_name}\&quot; id=\&quot;{$name}{$val}\&quot; &quot;
						. &quot;value=\&quot;{$val}\&quot;&quot;
						. $this-&gt;addOptions($value_excluded=true)
						. $checked
						. &quot; /&gt;\n&quot;
						. &quot;&lt;label for=\&quot;{$name}{$val}\&quot;&gt;{$key}&lt;/label&gt;&quot; . $this-&gt;options['br'] . &quot;\n&quot;;
				$counter++;
			}
		}

		if (@$this-&gt;input_return) {
			return $input;
		} else {
			echo $input;
		}

	}
	/* ****************************************************************************************
	* END:::
	**************************************************************************************** */

/* ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
*
*
*
* 	The following methods are those that do not specifically involve form elements themselves
*	These methods assist in creating and formatting the elements and their values, but
*	hold no relevance on how to use the $forms class
*
*	No instructional value for use below this line. Only for core functionality
*
*
*
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: */

	/* ***********************************************************
	* START :::
	*	Simply outputs a given message with ID 'forms-message'
	*	redundancy brought this on
	*********************************************************** */
	function message($mess, $urgent='') {
		$urgent = empty($urgent)?'':' class=&quot;'.$urgent.'&quot;';
		if (!empty($mess)) :
			echo '&lt;p id=&quot;forms-message&quot;'.$urgent.'&gt;'.$mess.'&lt;/p&gt;';
		endif;
	}
	/* ***********************************************************
	* END :::
	*********************************************************** */

	/* **********************************************************
	* START :::
	* 	Handles opening and closing the &lt;form&gt; element tag
	********************************************************** */

		# open tag
		function start($params='') {
			global $config;

			$this-&gt;createVariables();

			$attribs=&quot;&quot;;

			$id=&quot;&quot;;
			$name=&quot;&quot;;

			# loop params and create the desired vars
			if (is_array($params)) :
				foreach ($params as $key=&gt;$val) :
					$$key = $val;
					$attribs .= &quot; {$key}=\&quot;{$val}\&quot;&quot;;
				endforeach;
			endif;

			$post_to = (isset($action))?$action:$this-&gt;self();

			echo &quot;&lt;form{$attribs} method=\&quot;post\&quot;&gt;&quot;;
		}

		# close tag
		function close() {
			global $config;
			echo '&lt;/form &gt;';
		}

	/* ***********************************************************
	* END :::
	*********************************************************** */

	/* ***********************************************************
	* START :::
	* 	method cleans up values being passed for the object's
	* 	value it checks to see if there is a POST value or a manual
	* 	$form-&gt;input_name assigned. If neither of those exist, it
	* 	will use whatever value is password in the $params array
	*********************************************************** */
	function cleanUpValue($strip=true) {		

		$input_name = $this-&gt;input_name;
		$input_name = str_replace('[]','',$input_name);

		$noninclude_name = str_replace('incl_','',$input_name);

		$input_value = $this-&gt;input_value;

		if (isset($_POST[$input_name]) &amp;&amp; !empty($_POST[$input_name])) :
			$input_value 	= $_POST[$input_name];
		endif;

		if (isset($this-&gt;$input_name)) :
			$input_value 	= $this-&gt;$input_name;

		elseif ( isset($this-&gt;$noninclude_name) ) :
			$input_value 	= $this-&gt;$noninclude_name;
		endif;

		if (@$strip &amp;&amp; is_string($input_value) ) :
			$input_value = str_replace('&quot;', '', $input_value);
			$input_value = $this-&gt;format-&gt;strChars($input_value);
		endif;

		$this-&gt;input_value = $input_value;

		return $input_value;
	}
	/* ***********************************************************
	  * END :::
	*********************************************************** */

	/* ***********************************************************
	* START :::
	* 	Adds each attribute to the element's tag
	* 	this is limitless since we loop thru the $param array
	*
	* 	If there are specific attributes that should be ignored,
	* 	add them to the $attributes_not_allowed object
	*********************************************************** */
	function addOptions($value_exclude=false) {
		$input='';

		# $options is not an array
		# it only contains the form element's value
		# create the $form-&gt;options array and assign
		# value to it and establish all other default
		if (!is_array($this-&gt;options)) :

			$this-&gt;input_value 		= $this-&gt;options;
			$this-&gt;options			= array();
			$this-&gt;options['value']	= $this-&gt;input_value;
			$this-&gt;options['class'] 	= $this-&gt;classes[$this-&gt;options['type']];
			$this-&gt;input_return 	= false;

		endif;

		$this-&gt;options 		= $this-&gt;returnValue();
		$this-&gt;input_value 		= $this-&gt;options['value'];

		/* **************************************************
		  * handle all value adjustments here */

			# if there is no class being assigned manually
			# use the defualt
			if (!isset($this-&gt;options['class'])) :
				$this-&gt;options['class'] = $this-&gt;classes[$this-&gt;options['type']];
			endif;

			# so we don't have to keep passing this value
			# from function to function, set the value
			# to a class object
			if (isset($this-&gt;options['value'])) :
				$this-&gt;input_value  = $this-&gt;options['value'];
			endif;

			# clean the value and determine if there
			# has been a submission or a manual override
			if (!$value_exclude) :
				$this-&gt;options['value'] 	= $this-&gt;cleanUpValue();
			else :
				$this-&gt;options['value'] 	= $this-&gt;cleanUpValue();
				$this-&gt;input_value 		= $this-&gt;options['value'];
			endif;
			# does the value need to be formatted using a custom method?
			if (isset($this-&gt;options['format'])) :

				$func = $this-&gt;options['format'];
				$func = 'return $this-&gt;format-&gt;'.$func.'(\''.$this-&gt;input_value.'\');';

				$this-&gt;input_value = eval($func);

				$this-&gt;options['value'] = $this-&gt;input_value;
			endif;

			if (@$value_exclude) :
				unset($this-&gt;options['value']);
			endif;

		/* ************************************************* */

		# attach all additional attributes to this element
		foreach ($this-&gt;options as $key=&gt;$val) :

			if ($key == 'return') :
				$this-&gt;input_return = $val;

			elseif ( !in_array($key, $this-&gt;attributes_not_allowed) ) :
				$input .= &quot; {$key}=\&quot;{$val}\&quot;&quot;;
			endif;

		endforeach;

		return $input;
	}
	/* ***********************************************************
	  * END :::
	*********************************************************** */

	/* ***********************************************************
	* START :::
	* 	this evaluates the $value being passed for this object
	* 	the $options object needs to be an array, but if there
	* 	are times when the value is not passed as an array
	* 	(ie. $form-&gt;input('field_name','value');)
	*
	* 	this method takes that value and adds it to the $options
	* 	object in the $value key
	*********************************************************** */
	function returnValue() {

		if (!is_array($this-&gt;options)) :
			$this-&gt;options = array('value'=&gt;$this-&gt;options);

		elseif ( !isset( $this-&gt;options['value'] ) ) :
			$this-&gt;options['value'] = '';

		endif;

		return $this-&gt;options;
	}
	/* ***********************************************************
	  * END :::
	*********************************************************** */

	/* **********************************************************************
	* START :::
	* Avoid erroring legacy calls.
	********************************************************************** */
	function echo_error() {
		return $this-&gt;method-&gt;echo_error();
	}

	function hasPost() {
		return $this-&gt;method-&gt;hasPost();
	}

	function validate() {
		return $this-&gt;method-&gt;validate();
	}

	function createVariables() {
		return $this-&gt;method-&gt;createVariables();
	}

	function setResults($sql) {
		return $this-&gt;method-&gt;setResults($sql);
	}

	function strChars( $value ) {
		return $this-&gt;method-&gt;strChars( $value );
	}

	function self() {
		return $this-&gt;post-&gt;self();
	}

	function httpReferer($set=false) {
		return $this-&gt;post-&gt;referer($set=false);
	}

	function in2Db($dbName='', $dbtable='', $uniqueKey='') {
		return $this-&gt;database-&gt;insert($dbName='', $dbtable='', $uniqueKey='');
	}
	/* **********************************************************************
	  * END :::
	********************************************************************** */
}
/* ************************************************************************************************
* END :::
************************************************************************************************ */

$form = new Forms();
?&gt;
</pre>
<p>&nbsp;</p>
<h2>Forms Configuration File (Forms.Config.php)</h2>
<p><em>used to establish some configuration settings throughout the Forms class</em></p>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php
	//
	// specify what required/excluded element names will start with
	// EX: required: &lt;input type=&quot;type&quot; name=&quot;incl_fieldName&quot; id=&quot;fieldName&quot; value=&quot;&quot; /&gt;
	// EX: excluded: &lt;input type=&quot;type&quot; name=&quot;_ex_fieldName&quot; id=&quot;fieldName&quot; value=&quot;&quot; /&gt;
	$this-&gt;required_indicator = 'incl_';
	$this-&gt;excluded_indicator = '_ex_';

	//
	// this is a common template used to build an auto-response email
	// use the full absolute path to the template
	$this-&gt;email_template = '';

	// default classes
	// used unless specified during method call
	$this-&gt;classes = array(
		'text'		=&gt; 'input',
		'password'	=&gt; 'password',
		'hidden'		=&gt; 'input',
		'submit'		=&gt; 'submit',
		'reset'		=&gt; 'reset',
		'button'		=&gt; 'button',
		'image'		=&gt; 'image',
		'textarea'	=&gt; 'textarea',
		'select'		=&gt; 'select',
		'radio'		=&gt; 'radio',
		'checkbox'	=&gt; 'checkbox',
		'file'		=&gt; 'input'
	);

	// list of attributes you do not want to have added to an element
	$this-&gt;attributes_not_allowed = array(
		'type',
		'default',
		'checked',
		'selected',
		'br',
		'is_array'
	);

	// reserved items specifically for the db calls.
	$this-&gt;reserved = array(
		#
		# indicate, in an array, what you want to strip from a post name
		# when the post name is displayed to user during times such as
		# errors and/or emails. the replace_what and replace_with must be in the same order
		'replace_what'			=&gt; array( $this-&gt;required_indicator, '_', '-' ),  // the excluded/included indicators are automatically added to this list
		'replace_with'			=&gt; array( '', '', '', ' ', ' '),

		#
		# used to specify if you have field that should be unique in value
		# ex: once a user id is used, no one can use it
		'unique_column_name'	=&gt; array(),

		#
		# if the database table contains a specific &quot;created on&quot; date field
		# this is the field name
		'created_date_column'	=&gt; array(),

		#
		# this is name of the field to indicate the form submitted is the only form
		# you want to have automatically included in the &quot;insert&quot; statement
		'customFormIndicator'	=&gt; 'custom_form'
	);

	$this-&gt;format;
	$this-&gt;email='';
	$this-&gt;error='';
	$this-&gt;message='';

	$this-&gt;input_name;
	$this-&gt;input_value;
	$this-&gt;options;
	$this-&gt;value_exclude = false;

	# used for extensions
	$this-&gt;method;		// $form-&gt;method-&gt;hasPosts()
	$this-&gt;database;	// $form-&gt;database-&gt;insert()
	$this-&gt;post;		// $form-&gt;post-&gt;referer();
?&gt;
</pre>
<p>&nbsp;</p>
<h2>Formatting Class (Forms.Method.Formatting.php)</h2>
<p><em>use this class to add additional formatting methods. Phone number formatting is already included.</em></p>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php
/* ****************************************************************************
  * START :::
  *
  * You can add aditional format functionality to the Forms class if you wish
  * This allows you to pass a 'format' attribute with the name of the method
  * and have the element's value formatted according to your custom method.
  *
  * An example below is for phone numbers. To use, simply do the following
  * 		$form-&gt;input('field_name',array('value'=&gt;'9185551212','format'=&gt;'phone'));
  *
  *		input value formatted to '(918) 555-1212'
  *
  * This looks for the &quot;phone&quot; method, passes the value to the method and
  * the phone method returns the formatted value
  *
**************************************************************************** */

	class Forms_Formatting {

		/* ***********************************************************
		*
		* START :::
		*	formats phone number according to length of number
		* 	7 digits formatted to 555-1212
		* 	10 digits formatted to (555) 555-1212
		*
		*********************************************************** */

		function phone($value='') {
			$value = preg_replace(&quot;/[^0-9]/&quot;, &quot;&quot;, $value);

			if(strlen($value) == 7) :
				$value = preg_replace(&quot;/([0-9]{3})([0-9]{4})/&quot;, &quot;$1-$2&quot;, $value);

			elseif(strlen($value) == 10) :
				$value = preg_replace(&quot;/([0-9]{3})([0-9]{3})([0-9]{4})/&quot;, &quot;($1) $2-$3&quot;, $value);

			endif;

			return $value;
		}

		/* ***********************************************************
		* END :::
		*********************************************************** */

		/* **********************************************************************
		* START :::
		*	Strips unwanted characters
		*	Replaces single and double quotes with HTML equivalents
		********************************************************************** */
			function strChars( $value ) {
				global $form;

				$bad = array('&amp;quot;','&amp;lsquot;');
				$good = array('&quot;',&quot;'&quot;);

				if (!is_array($value)) :
					$value = stripslashes($value);
					$value = str_replace($bad,$good,$value);
				endif;
				return $value;
			}
		/* **********************************************************************
		  * END :::
		********************************************************************** */

	}

/* ****************************************************************************
* END :::
**************************************************************************** */
?&gt;
</pre>
<p>&nbsp;</p>
<h2>Forms Methods (Forms.Method.Methods.php)</h2>
<p><em>additional methods that didn&#8217;t belong anywhere specific. these are methods that are called by multiple classes and are universal</em></p>
<ul>
<li>
<p><strong>Edit 06-23-2010: </strong></p>
<ul>
<li>Corrected a $this reference in the echo_error() method</li>
<li>Fixed an is_array evaluation error in the checkbox method.</li>
</ul>
</li>
</ul>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php
/* ************************************************************************************************
*
* START :::
* 	These are all additional methods that are used for processing form elements.
* 	in order to better separate some of the code, we are pulling those methods away
* 	from the elements methods and placing them in the Forms_Methods class
*
************************************************************************************************ */
class Forms_Methods {

	/* **********************************************************************
	* START :::
	* test to verify a given value, in the specified DB/table is unique
	*
	* Required:
	*	$field		: the name of $_POST object (ie. $form-&gt;fieldname)
	*				  which we need to lookup. should match both the
	*				  table's field name and $_POST object
	*	$table		: the table to use for the lookup
	*
	*	Optional:
	*		$db_name 	: you can specify a DB name if the table is not
	*				  in the current DB
	*
	********************************************************************** */
	function isItUnique( $params ) {
		global $db, $form;

		$db_name = '';

		foreach ($params as $key=&gt;$val) :
			// prevent reserved words from being used
			if ($key == 'db' || $key == 'database') :
				$db_name = $val;
			else :
				$$key = $val;
			endif;
		endforeach;		

		$db_field_name = str_replace( array($form-&gt;required_indicator,$form-&gt;excluded_indicator), '', $field);

		$field_value = $form-&gt;$field;

		$sql = &quot;SELECT $db_field_name FROM $db_name.$table WHERE $db_field_name = '$field_value'&quot;;
		$sql = $db-&gt;query($sql);

		$unique = ($db-&gt;num_rows() &gt; 0) ? false : true;
		return $unique;
	}
	/* **********************************************************************
	  * END :::
	********************************************************************** */

	/* **********************************************************************
	* START :::
	* 	echos the form error to screen
	********************************************************************** */
	function echo_error() {
		global $form;

		if ( !empty($form-&gt;message) ) :
			echo '&lt;p id=&quot;form-message&quot;&gt;' . $form-&gt;message . '&lt;/p&gt;';
		endif;

		if ( !empty($form-&gt;error) ) :
			$form-&gt;error = '&lt;ul id=&quot;form-error&quot;&gt;'
						. '&lt;li class=&quot;form-error-header&quot;&gt;The following problems were found:&lt;/li&gt;'
						. $form-&gt;error
						. '&lt;/ul&gt;';
			echo $form-&gt;error;
		endif;
	}
	/* **********************************************************************
	  * END :::
	********************************************************************** */

	/* **********************************************************************
	* START :::
	* returns true if the $_POST array is set
	********************************************************************** */
	function hasPost() {
		if (count($_POST) &gt; 0 ) :
			return true;
		endif;

		return false;
	}
	/* **********************************************************************
	  * END :::
	********************************************************************** */

	/* **********************************************************************
	* START :::
	* Validates form submission.
	*
	* Required fields should have the $form-&gt;included_indicator at the
	* beginning of their names.
	*
	* Fields to be excluded should have $form-&gt;excluded_indicator at
	* the beginning
	********************************************************************** */
	function validate() {
		global $form;

		$form-&gt;loopcount=0;
		unset($_POST['x'], $_POST['y']);

		$incl = $form-&gt;required_indicator;
		$excl = $form-&gt;excluded_indicator;

		$form-&gt;fieldCount = count($_POST);
		$is_valid = true;

		# Loop through the $_POST array
		foreach ($_POST as $key=&gt;$val) {

			$excluded = (bool) strchr($key,$excl);
			if (!@$excluded) :

				$post['key'] = $key;
				$val = (is_array($val))?implode(', ',$val):$val;
				$post['val'] = $val;

				# if a required field is left blank, create an error list
				# append to the existing list so we can output error
				if ( strchr($post['key'], $incl) &amp;&amp; empty($post['val']) ) :
					$error_key = str_replace(array('incl_','_'),array('',' '), $post['key']);
					$error_key = ucwords($error_key);
					$form-&gt;error .= '&lt;li&gt;'.$error_key.' is required&lt;/li&gt;';
					$is_valid = false;
				endif;
			endif;
		}

		return $is_valid;

	}
	/* **********************************************************************
	  * END :::
	********************************************************************** */

	/* ******************************************************
	* START :::
	* loops thru $_POST array and creates $form objects
	* based on the $_POST array
	* 	$_POST['user_id']
	* 	$_POST['first_name']
	* would yield
	* 	$form-&gt;user_id
	* 	$form-&gt;first_name
	****************************************************** */
	function createVariables() {
		global $form, $db;

		foreach ($_POST as $key=&gt;$val) {
			if (!is_array($val) &amp;&amp; !empty($val)) {
				$form-&gt;$key = mysql_real_escape_string($val);
				$form-&gt;posts[$key] = $val;
			} else {
				$key = str_replace('[]','',$key);
				$form-&gt;$key = $val;
				$form-&gt;posts[$key] = $val;
			}
		}
	}
	/* ******************************************************
	  * END :::
	****************************************************** */

	/* ******************************************************
	* START :::
	* 	Will automatically create the Form variables based
	* 	on SQL results
	*
	*	Will use the SQL result set you pass to it and
	*	automcatically create $form objects from the results
	*
	*	Example:
	*		$sql = &quot;SELECT id, name, email FROM contacts&quot;;
	*		$form-&gt;setResults($sql);
	*
	*		// will create the following variables
	*			$form-&gt;id;
	*			$form-&gt;name;
	*			$form-&gt;email;
	****************************************************** */
	function setResults($sql) {
		global $form, $db;

		$i=0;
		$ret = array();
		$sql = $db-&gt;query($sql);
		while ($row = mysql_fetch_assoc( $sql )) {
			foreach ($row as $key=&gt;$val) {
				$form-&gt;$key = $val;
			}
		}
	}
	/* ******************************************************
	  * END :::
	****************************************************** */

	function email() {
		global $form;

		if ( !empty($form-&gt;email_template) &amp;&amp; is_file($form-&gt;email_template) ) :
			ob_start();
				include($form-&gt;email_template);
				$file_contents = ob_get_contents();
			ob_end_clean();
			$this-&gt;body = $form-&gt;file_contents;
		endif;

	}

}
/* ************************************************************************************************
* END :::
************************************************************************************************ */
?&gt;
</pre>
<p>&nbsp;</p>
<h2>Database Method (Forms.Method.Database.php)</h2>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php
/* ************************************************************************************************
*
* START :::
* 	Two Methods:
* 		insert(): called when a form submission is supposed to be INSERTed into DB
* 			this is a simple &amp; straight forward INSERT and nothing fancy
* 			If you have required/excluded fields, use the configuration variables at the top
* 			to set those
* 			REQUIRED FIELDS: left blank will have the specific chars removed and replaced
* 				The following are removed entirely
* 				$form-&gt;required_indicator
* 				$form-&gt;excluded_indicator
* 				'-'
* 			'_' is replaced with a space. The field name is then ucwords and used as the description
* 			of the required field for the error output
* 			EXAMPLE:
* 				Field Name: incl_first_name
* 				Error Output: First Name is required
*
* 		sql(): used by the insert() method to build the sql fields and values. not to be called
* 			independantly
*
************************************************************************************************ */
class Forms_DB {

	var $sqlFields='';
	var $sqlValues='';
	var $counter=0;

	var $comma=',';
	var $fieldCount=0;

	/* ******************************************************
	* START :::
	*   Loop through the $_POST array and build the insert
	*   statement.
	*
	*   Any required fields left blank are added to an
	*   error object
	****************************************************** */
	function insert($database='', $table='', $unique_column_name='') {
		global  $config,
				$db,
				$app,
				$form;

		$unique_columns = empty($unique_column_name) ? $form-&gt;reserved['unique_column_name'] : $unique_column_name;

		unset($_POST['x'], $_POST['y']); // can't remember the purpose of this. may have to remove and see what breaks

		if ( is_array($database) ) :
			foreach ($database as $key=&gt;$val) :
				$$key = $val;
			endforeach;
		endif;

		$this-&gt;loopcount=0;
		$this-&gt;fieldCount = count($_POST);

		if ( isset($unique_columns) &amp;&amp; is_array( $unique_columns ) ) :
			$uni_col = array();
			foreach ($unique_columns as $column) :
				$uni_col[] = $column;
			endforeach;
			$unique_columns = $uni_col;

		elseif ( isset($unique_columns) &amp;&amp; !is_array($unique_columns)) :
			$uni_col = array();
			$uni_col[] = $unique_columns;
			$unique_columns = $uni_col;

		endif;

		$unique_count = 0;
		foreach ($unique_columns as $key=&gt;$column) :

			# should column value be unique?
			if ($unique_count == 0 &amp;&amp; isset($_POST[$column]) &amp;&amp; !empty($_POST[$column]) ) :

				# strip the required/exluded indicators from the column name to get to the actual DB column name
				$column_name	= str_replace($form-&gt;reserved['column_type_indicators'], '', $column);
				$val 			= $_POST[$column];

				# check if a record exists with that value for that column
				$sql 			= &quot;SELECT id FROM {$database}.{$table} WHERE {$column_name} = '$val'&quot;;
				$sql 			= $db-&gt;query($sql);
				$unique_count 	= $db-&gt;num_rows();

				# a record was found. create the error
				if ($unique_count &gt; 0) :
					$error_key = str_replace( array('_','-'), ' ', $column_name );
					$error_key = ucwords($error_key);
					$form-&gt;error .= '&lt;li&gt;'.$error_key.' already exists&lt;/li&gt;';
				endif;

			endif;
		endforeach;

		# no unique errors were encountered
		# build the SQL statement
		if ($unique_count == 0) :

			# Loop through the $_POST array
			foreach ($_POST as $key=&gt;$val) :

				$excluded = (bool) strchr( $key, $form-&gt;excluded_indicator );

				# when you have multiple forms on a page and you want to use this function
				# sparingly, create a hidden input named whatever you wish.
				# $this-&gt;reserved-&gt;customFormIndicator should equal the name of that field
				# this ignores that field in the loop and deducts it from the counter
				if ($key == $form-&gt;reserved['customFormIndicator'] || @$excluded) :
					$this-&gt;fieldCount = $this-&gt;fieldCount-1;
					unset($_POST[$key]);

				else :

					if ( !$excluded ) :

						$post['key'] = $key;
						$val = (is_array($val))?implode(', ',$val):$val;
						$post['val'] = $val;

						# if a required field is left blank, create an error list
						# append to the existing list so we can output error
						if ( strchr($post['key'], $form-&gt;required_indicator) &amp;&amp; empty($post['val']) ) :
							$error_key = str_replace( $form-&gt;reserved['replace_what'], $form-&gt;reserved['replace_with'], $post['key']);
							$error_key = ucwords($error_key);
							$form-&gt;error .= '&lt;li&gt;'.$error_key.' is required&lt;/li&gt;';

						elseif ( empty($error_key) ):

							$val = (is_array($val))?implode(', ',$val):$val;
							$this-&gt;sql($post); // create the SQL code

							# You can create an email template so that the values are automatically plugged into the content
							# as we loop, this replaces %%field_name%% with its actual value
							# you can then use that to send an email with populated values
							if (!empty($form-&gt;email-&gt;body)) :
								$replace_what = str_replace('[]','',$post['key']);
								$form-&gt;email-&gt;body = str_replace('%%'.$replace_what.'%%', $post['val'], $form-&gt;email-&gt;body);
							endif;

						endif;

					endif;

				endif;

			endforeach;

		endif;

		# all required fields are filled out and there are no errors
		# insert into database table
		if ( empty($form-&gt;error) ) :

			if ( !empty( $form-&gt;reserved['created_date_column'] ) ) :
				$tableFields = mysql_list_fields($dbName, $dbtable);

				$columns = mysql_num_fields($tableFields);

				for ($i = 0; $i &lt; $columns; $i++) :
				    $field_array[] = mysql_field_name($tableFields, $i);
				endfor;

				if (in_array($form-&gt;reserved['created_date_column'], $field_array)) :
					$this-&gt;sqlFields .= &quot;, &quot; . $form-&gt;reserved['created_date_column'];
					$this-&gt;sqlValues .= ', NOW()';
				endif;
			endif;

			# insert into database
			$sql = &quot;INSERT INTO {$database}.{$table} (&quot;.$this-&gt;sqlFields.&quot;) VALUES (&quot;.$this-&gt;sqlValues.&quot;)&quot;;
			$sql = $db-&gt;query($sql);

			# get the newly created ID from table
			$sql = &quot;SELECT id FROM {$database}.{$table} WHERE id = LAST_INSERT_ID()&quot;;
			$this-&gt;new_id = $db-&gt;fetch_value($sql);

		# there were errors found. build out the complete error and pass it on
		else :
			$form-&gt;error = '&lt;ul id=&quot;form-error&quot;&gt;'.$form-&gt;error.'&lt;/ul&gt;';
		endif;
	}

		// simply puts together the SQL fields and values for the INSERT statement
		// in the insert() method
		function sql($post) {
			global $app;

			$tableColumn = str_replace(&quot;incl_&quot;, &quot;&quot;, $post['key']);
			$formField = $post['key'];

			# Lets setup the Field list for the Insert Statement
			$this-&gt;comma=($this-&gt;counter &gt; 0)?',':'';

			# if the value is an array, split the values with a comma
			$post['val'] = (is_array($post['val']))?implode(&quot;, &quot;, $post['val']):$post['val'];
			$post['val'] = mysql_real_escape_string($post['val']);

			$$formField = $post['val'];
			$this-&gt;sqlFields .= $this-&gt;comma.$tableColumn;
			$this-&gt;sqlValues .= $this-&gt;comma.&quot;'&quot;.$$formField.&quot;'&quot;;

			$this-&gt;counter++;
			# End Insert Build
		}
	/* ******************************************************
	* END :::
	****************************************************** */
}
/* *******************************************************************************************
* END :::
******************************************************************************************* */
?&gt;
</pre>
<p>&nbsp;</p>
<h2>Forms Post Class (Forms.Method.Post.php)</h2>
<p><em>used for gathering post information so the form can post back to itself or back to the referring page.</em></p>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php
/* *******************************************************************************************
  * START :::
  * 		This class has two methods
  * 		self(): used in the form tag's &quot;action&quot; attrib. Will get the URL of the form
  * 			so the form posts back to itself
  *
  * 		referer(): returns the full URL of the referring page
  *
******************************************************************************************* */
class Forms_Post {

	/* ***********************************************************
	* START :::
	*	Returns a full URL for the referer
	*	Differs from other methods because ensures the full
	*	domain, path and query string are included
	*********************************************************** */
	function self() {
	    /*** check for https ***/
	    $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
	    /*** return the full address ***/
	    return $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
	}
	/* ***********************************************************
	* END :::
	*********************************************************** */

	/* ***********************************************************
	* START :::
	*	Returns a full URL for the referer
	*	Differs from other methods because ensures the full
	*	domain, path and query string are included
	*********************************************************** */
	function referer($set=false) {
	    /*** check for https ***/
	    $protocol = $_SERVER['HTTPS'] == 'on' ? 'https' : 'http';
	    /*** return the full address ***/
	    $url = $protocol.'://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

		// Are setting this to a variable, or echoing it?
		if (!$set) :
			echo $url;
		else :
			return $url;
		endif;
	}
	/* ***********************************************************
	* END :::
	*********************************************************** */

}
/* *******************************************************************************************
* END :::
******************************************************************************************* */
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/100/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 1/17 queries in 0.116 seconds using disk: basic
Object Caching 281/318 objects using disk: basic

Served from: jjis.me @ 2012-02-06 11:22:55 -->
