<?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; code</title>
	<atom:link href="http://jjis.me/a/tag/code-2/feed" rel="self" type="application/rss+xml" />
	<link>http://jjis.me</link>
	<description>Me And My Code</description>
	<lastBuildDate>Mon, 30 Apr 2012 17:58:52 +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>I forgot about this hidden gem: Internet Explorer and Fade-In pitfalls</title>
		<link>http://jjis.me/a/407</link>
		<comments>http://jjis.me/a/407#comments</comments>
		<pubDate>Thu, 16 Sep 2010 15:48:23 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[jQuery & Javascript]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=407</guid>
		<description><![CDATA[jQuery&#8217;s fadeIn() method is a wonderful thing. It&#8217;s a great way to bring things in and out of the UI without a sudden jolt, visually. The downside to this, however, is Internet Explorer and the way it handles filters for transparency. When an element is faded in, and it contains fonts, IE does not remove [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery&#8217;s fadeIn() method is a wonderful thing. It&#8217;s a great way to bring things in and out of the UI without a sudden jolt, visually. The downside to this, however, is Internet Explorer and the way it handles filters for transparency. When an element is faded in, and it contains fonts, IE does not remove the filter by default. This prevents the fonts from smoothing like they should.</p>
<h2>Internet Explorer post standard jQuery fadeIn() method</h2>
<p><a href="http://jjis.me/wp-content/uploads/2010/09/ie-fadeIn-filter-effects.jpg"><img class="size-full wp-image-408 alignnone" title="Internet Explorer with jQuery fadeIn() filter effects" src="http://jjis.me/wp-content/uploads/2010/09/ie-fadeIn-filter-effects.jpg" alt="" width="600" height="91" /></a></p>
<p><span id="more-407"></span></p>
<p>In searching for a solution, I stumbled across a rather simple removeFilter() method someone created. This worked nice, but it meant you had to do chaining or a callback in order for the fadeIn() to work and then have the filter removed so the fonts would smooth. I&#8217;m lazy and I like to do everything in a single method if I can. So, let combine the fadeIn/fadeOut methods in to a single method and add the filter removal as well.</p>
<pre class="brush: jscript; title: ; wrap-lines: false; notranslate">
(function($) {
	 $.fn.removeFilter = function() {
		if ($.browser.msie) {
			x = this.get(0)
			x.style.removeAttribute(&quot;filter&quot;);
		 }
	 }
})(jQuery);

(function($){
	 $.fn.fadeToggle = function(options) {
		  options  = typeof(options) != 'undefined'?options:'';
		  speed    = typeof(options.speed)!='undefined'?options.speed:'';
		  easing   = typeof(options.easing)!='undefined'?options.easing:'';
		  callback = typeof(options.callback)!='undefined'?options.callback:'';
		  callback = function(callback) {
			   $(this).removeFilter();
			   callback;
		  }

		  this.animate(
			   {opacity: 'toggle'},
			   speed,
			   easing,
			   callback
		  );
	 }
})(jQuery);
</pre>
<p>&nbsp;</p>
<h2>Use:</h2>
<pre class="brush: jscript; title: ; notranslate">
// normal speed
$('#objectId').fadeToggle();

// set fade in/out speed
$('#objectId').fadeToggle({ speed: 'fast' });
</pre>
<p>&nbsp;</p>
<h2>Internet Explorer post fadeToggle() method</h2>
<p><a href="http://jjis.me/wp-content/uploads/2010/09/ie-fadeToggle.jpg"><img src="http://jjis.me/wp-content/uploads/2010/09/ie-fadeToggle.jpg" alt="" title="Internet Explorer with fadeToggle method" width="600" height="91" class="alignnone size-full wp-image-411" /></a></p>
<p>&nbsp;</p>
<h2>Using removeFilter() method as a standalone method</h2>
<p>There may instances where you just need to remove the filter. In that case, the following works:</p>
<pre class="brush: jscript; title: ; wrap-lines: false; notranslate">

// as callback within fadeIn() method
$('#objectId').fadeIn('fast', function() {
        $(this).removeFilter();
});

// simply remove the filer on a specific object or objects
$('#objectId').removeFilter();
</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/407/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inline Images With Data URLs</title>
		<link>http://jjis.me/a/362</link>
		<comments>http://jjis.me/a/362#comments</comments>
		<pubDate>Wed, 11 Aug 2010 22:16:49 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=362</guid>
		<description><![CDATA[This particular trick comes in very handy for the mobile platforms. Instead of linking to your CSS and your images, you can use this method to embed the images inline within the CSS. This keeps the browser from having to make multiple calls, thus speeding up the load time of your application. You can also [...]]]></description>
			<content:encoded><![CDATA[<p>This particular trick comes in very handy for the mobile platforms. Instead of linking to your CSS and your images, you can use this method to embed the images inline within the CSS. This keeps the browser from having to make multiple calls, thus speeding up the load time of your application. You can also use this method within an IMG tag as well.</p>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
	/* ***********************************************************
	* START :::
	*	64bit encodes images for CSS embedding
        *      Alternatively, if you are not using PNGs, you can specify the Mime Type
        *      PNG is the default mime
	*********************************************************** */
	function data_url($file, $mime='') {  

		$mime = empty($mime) ? 'image/png' : $mime;

		$contents = file_get_contents($file);
		$base64   = base64_encode($contents);
		return ('data:' . $mime . ';base64,' . $base64);
	}
	/* ***********************************************************
	* END :::
	*********************************************************** */
</pre>
<h2>In the CSS style sheet</h2>
<p>You would need to either tell your server to process files with the .css extension or save your CSS files with the .php extension. It&#8217;s your call.</p>
<pre class="brush: css; title: ; wrap-lines: true; notranslate">

 body { background-image: url('&lt;?php echo data_url('http://domain.com/images/file.png'); ?&gt;') no-repeat; }

/* output code would be something like */
body { background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFQAAABUCAIAAACTCYeWAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAI5JREFUeNrs2sENACEIRUF1LY0mqRbb2OQPHUwexIu7qlbq3JmJxZ8VPMorr7zy8NZeeXhrrzw8vJtXHh4eHh7eU6c8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8fMj4kAQPDw8P76lTHh7ezSsPb+2Vh7f2yiv/7/mS8dHlo2d3dyz+CTAAYEXI+4xG4igAAAAASUVORK5CYII=') no-repeat; }
</pre>
<h2>Within HTML img tags</h2>
<pre class="brush: xml; title: ; wrap-lines: true; notranslate">

&lt;img src=&quot;&lt;?php echo data_url('http://domain.com/images/file.png'); ?&gt;&quot; border=0 /&gt;

&lt;!-- output code would be something like --&gt; &lt;img src=&quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFQAAABUCAIAAACTCYeWAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAI5JREFUeNrs2sENACEIRUF1LY0mqRbb2OQPHUwexIu7qlbq3JmJxZ8VPMorr7zy8NZeeXhrrzw8vJtXHh4eHh7eU6c8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8PDw8fMj4kAQPDw8P76lTHh7ezSsPb+2Vh7f2yiv/7/mS8dHlo2d3dyz+CTAAYEXI+4xG4igAAAAASUVORK5CYII=&quot; border=0 /&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/362/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error Handling</title>
		<link>http://jjis.me/a/327</link>
		<comments>http://jjis.me/a/327#comments</comments>
		<pubDate>Wed, 11 Aug 2010 04:44:17 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=327</guid>
		<description><![CDATA[In the world of the Internet, as a developer, we need to protect ourselves from prying eyes. One of the easiest ways a hacker can crack your code is if you tell them what they did wrong. For that reason, it&#8217;s important to suppress errors from the public. But, this doesn&#8217;t mean we should eliminate [...]]]></description>
			<content:encoded><![CDATA[<p>In the world of the Internet, as a developer, we need to protect ourselves from prying eyes. One of the easiest ways a hacker can crack your code is if you tell them what they did wrong. For that reason, it&#8217;s important to suppress errors from the public. But, this doesn&#8217;t mean we should eliminate the knowledge when an error occurs and what triggered it.  For that reason, I have written a fairly simple class that will allow for error suppression, error debugging and error reporting.</p>
<p><span id="more-327"></span></p>
<p>When in debug mode, the error is displayed on screen in a fairly elegant manner. Barring CSS overrides and surrounding DOM elements, the error is output in a legible manner so that it can be easily read.</p>
<p>When errors are suppressed, the error is caught and handled elegantly and then emailed to the specified email address.</p>
<p><strong><em>The one drawback: </em></strong> if there is a parse error in the file that includes the Error.Handling.Class.php file, it will not call this class. It will use PHP&#8217;s internal error handler and print the error to screen. If anyone knows a way around this, let me know and I will implement it.</p>
<h2>Examples:</h2>
<ul>
<li class="none"><a href="http://jjis.me/error.static.parse.php" target="_new">Parse error in debug mode</a></li>
<li class="none"><a href="http://jjis.me/error.static.exception.php" target="_new">Exception errors in debug mode</a></li>
<li class="none"><a href="http://jjis.me/error.static.suppressed.php" target="_new">Both errors when suppressed</a></li>
</ul>
<h2>Code:</h2>
<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
	*
	*	Error Catching and Debugging
	*
*/

class Error_Debug {
	#
	# a couple of basic settings
	#
	# Display Errors?:
	#	True|False
	#	This is overridden should there be a $config-&gt;show_errors var
	#
	# Email To:
	#	email for the person who needs to receive the error
	#
	# Style Sheet:
	#	Set the link to the style sheet.
	#	Exclude from the server path ( http://domain.com )
	#
	# Suppressed Error Message
	#	This is the error message that will be displayed if error reporting is turned off
	#
	var $errors = array(
			'display'     =&gt; false,
			'email_to'    =&gt; 'email@domain.com',
			'email_from'  =&gt; 'email@domain.com',
			'style_sheet' =&gt; 'css/error-reports.css',
			'suppressed_error_message' =&gt; '&lt;div align=&quot;center&quot;&gt;&lt;b style=&quot;font-size: 150%;&quot;&gt;lnnl&lt;b style=&quot;font-size: 200%;&quot;&gt; (-_-) &lt;/b&gt;lnnl&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;aw snap! something broke!&lt;/div&gt;'
		);

	function Error_Debug() { return true; }

	/* ***********************************************************************
	* START :::
	*
	*	Initial error catching method
	*	This will determine if it's a parse error, or other
	*	types of errors.
	*
	*	PARSE:
	*		stops everything dead in its tracks. If display
	*		errors is allowed, then show the error message
	*		otherwise suppress the error and email it
	*
	*
	*	ALL OTHERS:
	*		Run the backtrace through the previous called
	*		functions and display the information for debugging
	*		If display errors is false, suppress the error
	*		and email the error
	*********************************************************************** */
	function catch_error($n='', $s='', $f='', $l='') {
		global $security, $config;	

		#
		# check to see if the $config object exists. if so, use it's setting
		$this-&gt;errors['display'] = (isset($config-&gt;show_errors) ) ? $config-&gt;show_errors : $this-&gt;errors['display'];

		#
		# if this is a parse error, we need to handle it differently
		# because it completely stops all PHP parsing, we catch it immediately
		# and display a simple output
		if( empty($n) &amp;&amp; false === is_null($aError = error_get_last()) ) :

			#
			# suppress the error and show something entertaining
			if ( !$this-&gt;errors['display'] ) :
				echo $this-&gt;errors['suppressed_error_message'];

			#
			# for debugging, display the information about the error
			else :
				$err = error_get_last();
				$this-&gt;echo_css();
				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 Type: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot; . $err['type'] . &quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;
					. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;Message: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot; . $err['message'] . &quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;
					. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;File: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot; . $err['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;.$err['line'].&quot;&lt;/td&gt;&lt;/tr&gt;\n&lt;/table&gt;\n&quot;;

			endif;

		#
		# exception errors get sent to either backtracing or suppression
		else :

			#
			# backtrace the error and display the information for debugging
			if ( @$this-&gt;errors['display'] ) : $this-&gt;error_backtrace($n, $s, $f, $l);

			#
			# suppress the error and email it
			else : $this-&gt;error_thrown($n, $s, $f, $l); 

			endif;

			return true;

		endif;
		exit();
	}
	/* ***********************************************************************
	* END :::
	*********************************************************************** */

	/* ***********************************************************************
	* START :::
	*
	*	Backtraces through the errors and displays a nice
	*	It's pretty simple. Not a lot that needs explaining
	*
	*********************************************************************** */
	function error_backtrace($errno, $errstr, $error_file, $error_line) {
		global $css;

		$errorsThrown = debug_backtrace();

		#
		# we skip the first two errors
		# they are the initial calls from error catching
		# we can ignore them
		#
		if ( isset($errorsThrown[2]) ) :
			$errorThrown  = $errorsThrown[2];

			#
			# echo css
			$this-&gt;echo_css();

			#
			# this is the primary error that started it all
			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;&quot; . $errstr . &quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;
				. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;Line: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot; . $error_line . &quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;
				. &quot;&lt;tr&gt;&lt;td class=\&quot;left\&quot;&gt;&lt;strong&gt;File: &lt;/strong&gt;&lt;/td&gt;&lt;td&gt;&quot; . $error_file . &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;;

			#
			# for additional debugging, loop through all previous function calls
			# this assists in debugging if you call a method multiple times
			# now we can figure out which instance caused the error
			#
			echo &quot;&lt;p&gt;All previously executed functions: &lt;/p&gt;\n&quot;;

			echo &quot;&lt;table id=\&quot;previous-errors\&quot; cellpadding=5 cellspacing=0 border=0 style=\&quot;border: 1px solid #333;\&quot;&gt;&quot;
				. &quot;&lt;tr style=\&quot;background: #d3d3d3;\&quot;&gt;&quot;
				. &quot;&lt;th&gt;order&lt;/th&gt;&quot;
				. &quot;&lt;th&gt;function name&lt;/th&gt;&quot;
				. &quot;&lt;th&gt;file name&lt;/th&gt;&quot;
				. &quot;&lt;th&gt;line&lt;/th&gt;&quot;
				. &quot;&lt;/tr&gt;&quot;;

			$count = 0;
			array_reverse($errorsThrown);

			#
			# loop thu the backtrace and output
			foreach ($errorsThrown as $error) :
				$is_db = (bool) strchr($error['file'], 'Database.php');
				if ($count &gt; 1 &amp;&amp; !$is_db) :
					echo '&lt;tr&gt;'
					. '&lt;td&gt;' . ($count-1) . '&lt;/td&gt;'
					. '&lt;td&gt;' . $error['function'] . '()&lt;/td&gt;'
					. '&lt;td&gt;' . $error['file'] . '&lt;/td&gt;'
					. '&lt;td&gt;' . $error['line'] . '&lt;/td&gt;'
					. '&lt;/tr&gt;';
				endif;
				$count++;

			endforeach;

			#
			# close it all up
			echo '&lt;/table&gt;'
				. '&lt;p&gt;&amp;nbsp;&lt;/p&gt;'
				. '&lt;/div&gt;&lt;/div&gt;';
		exit();
		endif;
	}
	/* ***********************************************************************
	* END :::
	*********************************************************************** */

	/* ***********************************************************************
	* START :::
	*
	*	Backtraces through the errors and displays a nice
	*	It's pretty simple. Not a lot that needs explaining
	*
	*********************************************************************** */
	function error_thrown($errno, $errstr, $error_file, $error_line) {
		global $security;

		$errorThrown = debug_backtrace();
		$errorFunction = '';

		#
		# we skip the first two errors
		# they are the initial calls from error catching
		# we can ignore them
		#
		if (isset($errorThrown[2])) :
			$errorThrown = $errorThrown[2];
			$errorFunction = &quot;\n&quot;.'Calling Function: '.$errorThrown['function'];

			$referer = (isset($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : '';

			$server_r = '';
			$server_out = $_SERVER;
			foreach ($server_out as $key=&gt;$val) {
				$server_r .= $key.' ::: '.$val.&quot;\n\r&quot;;
			}

			$message = '';
			$message .= &quot;Error Thrown: [{$errno}] {$errstr}{$errorFunction}\n&quot;
					. &quot;File Name: {$error_file}\n&quot;
					. &quot;On line: {$error_line}\n&quot;
					. &quot;Server: &quot; . $_SERVER['SERVER_NAME'] . &quot;\n&quot;
					. &quot;URL: &quot; . $_SERVER['REQUEST_URI'] . &quot;\n&quot;
					. &quot;Referer: {$referer}&quot;
					. &quot;\n\n\n&quot;
					. &quot;Server Output: \n&quot;
					. $server_r
					. &quot;\n&quot;;

			if ( !error_log(
				$message, 1,
				$this-&gt;errors['email_to'],
				&quot;From: &quot; . $this-&gt;errors['email_from']
				)
			) :

				echo $this-&gt;errors['suppressed_error_message'];

			endif;
		endif;
	}
	/* ***********************************************************************
	* END :::
	*********************************************************************** */

	/* ***********************************************************************
	* START :::
	*
	*	echo the css style sheet so the error reporting is pretty
	*
	*********************************************************************** */
	function echo_css() {
		$css_url = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $this-&gt;errors['style_sheet'];

		echo '&lt;link rel=&quot;stylesheet&quot; id=&quot;mainstyle&quot; type=&quot;text/css&quot; href=&quot;' . $css_url . '&quot; /&gt;';
	}
	/* ***********************************************************************
	* END :::
	*********************************************************************** */

}

	# Upon All Errors, call the error handling function
	 	set_error_handler(array(new Error_Debug(),'catch_error'));

	# Register function to execute at the end of the script
		register_shutdown_function(array(new Error_Debug(),'catch_error'));

	# Hide error messages
		error_reporting(0);
?&gt;
</pre>
<h2>Some CSS styling for you: </h2>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
#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; }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/327/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Tabs With Ease</title>
		<link>http://jjis.me/a/280</link>
		<comments>http://jjis.me/a/280#comments</comments>
		<pubDate>Sat, 03 Jul 2010 01:50:19 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[jQuery & Javascript]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=280</guid>
		<description><![CDATA[As usual, I always need something special in jQuery. I&#8217;m always able to find plugins out there, but they never everything I want, the way I want it done. Each always falls short somewhere. It either limits my design flexibility, is buggy or is just flat-out bloated with way more code than is necessary. I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>As usual, I always need something special in jQuery. I&#8217;m always able to find plugins out there, but they never everything I want, the way I want it done. Each always falls short somewhere. It either limits my design flexibility, is buggy or is just flat-out bloated with way more code than is necessary.</p>
<p>I&#8217;ve written a tabs script for jQuery that is short and to the point while still allowing for design flexibility and ease. There&#8217;s nothing to it. Simply establish the tabs settings with your appropriate IDs and classes and you&#8217;re good to go. I&#8217;ve used on a few occasions and it has yet to fail me.</p>
<p>As usual, however, let me know if you have problems. I&#8217;ve supplied complete code for HTML, CSS and, of course, the jQuery/JavaScript.</p>
<p><span id="more-280"></span></p>
<h2></h2>
<h2>Let&#8217;s Start With The HTML</h2>
<pre class="brush: xml; title: ; wrap-lines: false; notranslate">
&lt;div id=&quot;tabs&quot;&gt;
	&lt;b class=&quot;active&quot;&gt;&lt;a href=&quot;#selected-categories&quot;&gt;Currently Selected Categories&lt;/a&gt;&lt;/b&gt;
	&lt;b class=&quot;inactive&quot;&gt;&lt;a href=&quot;#all-categories&quot;&gt;All Available Categories&lt;/a&gt;&lt;/b&gt;
&lt;/div&gt;

&lt;ul id=&quot;selected-categories&quot; class=&quot;tab&quot;&gt;
        &lt;li id=&quot;item1&quot; class=&quot;li-item&quot;&gt;Item 1 text&lt;/li&gt;
        &lt;li id=&quot;item2&quot; class=&quot;li-item&quot;&gt;Item 3 text&lt;/li&gt;
        &lt;li id=&quot;item3&quot; class=&quot;li-item&quot;&gt;Item 7 text&lt;/li&gt;
        &lt;li id=&quot;item3&quot; class=&quot;li-item&quot;&gt;Item 8 text&lt;/li&gt;
&lt;/ul&gt;
&lt;ul id=&quot;all-categories&quot; class=&quot;tab&quot;&gt;
        &lt;li id=&quot;item1&quot; class=&quot;li-item&quot;&gt;Item 1 text&lt;/li&gt;
        &lt;li id=&quot;item2&quot; class=&quot;li-item&quot;&gt;Item 2 text&lt;/li&gt;
        &lt;li id=&quot;item3&quot; class=&quot;li-item&quot;&gt;Item 3 text&lt;/li&gt;
        &lt;li id=&quot;item3&quot; class=&quot;li-item&quot;&gt;Item 4 text&lt;/li&gt;
        &lt;li id=&quot;item1&quot; class=&quot;li-item&quot;&gt;Item 5 text&lt;/li&gt;
        &lt;li id=&quot;item2&quot; class=&quot;li-item&quot;&gt;Item 6 text&lt;/li&gt;
        &lt;li id=&quot;item3&quot; class=&quot;li-item&quot;&gt;Item 7 text&lt;/li&gt;
        &lt;li id=&quot;item3&quot; class=&quot;li-item&quot;&gt;Item 8 text&lt;/li&gt;
&lt;/ul&gt;
</pre>
<h2>The CSS</h2>
<pre class="brush: css; title: ; wrap-lines: false; notranslate">
/* *****
* tab header properties
***** */
#tabs { margin: 0 0 -2px 0; height: 45px; }
	#tabs b { display: block; float: left; margin: 0px; background: #fff; font-weight: normal; }
	#tabs b.active { background: #e0d3e3; }
		#tabs b a { display: block; color: #a989b0; padding: 10px; border: 1px solid #d3d3d3; text-decoration: none; }
		#tabs b a:hover { background: #f5edf6; }

		#tabs b.active a { color: #663366; }
		#tabs b.inactive a:hover { background: #f5edf6; }

/* *****
* tab content
***** */
.tab { clear: both; width: 100%; height: 250px; margin: 0; padding: 0; overflow: hidden; overflow-y: scroll; background: #fff; border: 1px solid #d3d3d3; }
	.tab li { font-weight: normal; padding: 10px; border-bottom: 1px dotted #d3d3d3; cursor: pointer; color: #663366; }
	.tab li:hover { background: #e0d3e3; }
</pre>
<h2></h2>
<h2>The jQuery Code</h2>
<pre class="brush: jscript; title: ; wrap-lines: false; notranslate">

/* *************************************************
*
* configuration: settings for class &amp; ids of tab
* elements
************************************************* */
var tabs = {
	default_tab    : 0,                    // the # of the tab that should be shown on page load
	// the tab itself
	tab : {
		wrapper   : '#tabs',          // parent that wraps around each tab header
		container : 'b',                // the container that wraps around the clickable tab text
		clickable : 'a',                 // the clickable tab text
		_class     : {
			active   : 'active',   // class for the active tab
			inactive : 'inactive' // class for all inactive tabs
		}
	},
	// the content for each tab
	content : {
		_class  : '.tab'                 // class of the content for the tabs
	},

	/* *************************************************
	*
	* bind tabbing events
	*
	************************************************* */
	init : function() {
		$( tabs.tab.wrapper + ' ' + tabs.tab.clickable ).click(function() {
			var id 	= $(this).attr('href');
			var par 	= $(this).parent();

			// hide all tab content
			$.each( $( tabs.content._class ), function(i) {
				$( this ).css( 'display','none' );
			});

			// display the tab content chosen
			$( id ).css('display','block');

			// show the tab as clicked
			$.each( $( tabs.tab.wrapper + ' ' + tabs.tab.container ), function() {
				$( this ).removeClass( tabs.tab._class.active );
				$( this ).addClass( tabs.tab._class.inactive );
			});

			par.removeClass( tabs.tab._class.inactive );
			par.addClass( tabs.tab._class.active );

			return false;
		});

		// hide all tab content except the first tab
		$.each( $( tabs.content._class ), function(i) {
			if (i &gt; tabs.default_tab) {
				$( this ).css('display','none');
			}
		});
	}

};
</pre>
<h2></h2>
<h2>Now Initiate the Code</h2>
<pre class="brush: jscript; title: ; wrap-lines: false; notranslate">
$(document).ready(function() {
        /* ************************************
        * only initiate the tab function if tabs are preset */
	        if ( $('#tabs').length &gt; 0 ) {
		        tabs.init();
	        }
});
</pre>
<p>There you go. That&#8217;s all there is to it. The code is definitely portable and you could make it a plugin yourself if you wanted. I will get it setup to allow multiple sets of tabs per page and update when it&#8217;s completed.</p>
<h2>Example</h2>
<div id="tabs"><b class="active"><a href="#tab-a">Tab A</a></b><b class="inactive"><a href="#tab-b">Tab B</a></b></div>
<ul id="tab-a" class="tab">
<li id="item1" class="li-item">Item 1 text</li>
<li id="item3" class="li-item">Item 3 text</li>
<li id="item7" class="li-item">Item 7 text</li>
<li id="item8" class="li-item">Item 8 text</li>
</ul>
<ul id="tab-b" class="tab">
<li id="item2" class="li-item">Item 2 text</li>
<li id="item4" class="li-item">Item 4 text</li>
<li id="item5" class="li-item">Item 5 text</li>
<li id="item6" class="li-item">Item 6 text</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/280/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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 Class Code</h2>
<ul>
<li>
<p><strong>Updated 02-10-2012: </strong></p>
<ul>
<li>Renamed database class to Framework_Database to signify this class is a framework level class.</li>
<li>Most everything was re-written to tighten up the code.</li>
<li>Moved the database connection settings to a $config object. Allows for a single configuration file of your choosing.</li>
<li>Got rid of error_backtracing() and show_mysql_error() since it didn&#8217;t really work. It will now print the error to screen, via $db->error() (called automatically), if $config->errors['display'] is set to true. If false, it will email the error to $config->errors['email_to'].</li>
</ul>
</li>
</ul>
<p>Despite the re-write, your $db->query(), $db->fetch_object(), etc. methods are still there and still work the same.</p>
<pre class="brush: php; title: ; wrap-lines: false; notranslate">
&lt;?php
if ( !isset($config) ) :
	# ###
	#
	$config = (object) array();
		#
		# database connection settings
		$config-&gt;db = array(
			'host'                =&gt; '',
			'user'                =&gt; '',
			'password'            =&gt; '',
			'db_name'             =&gt; ''
		);

		#
		# error display settings
		$config-&gt;errors = array(
			'display'     =&gt; true,
			'redirect_to' =&gt; '/error',
			'email_to'    =&gt; 'email@yourdomain.com',
			'email_from'  =&gt; 'email@yourdomain.com',
			'style_sheet' =&gt; 'css/error-reports.css',
			'suppressed_error_message' =&gt; '&lt;div align=&quot;center&quot;&gt;&lt;b style=&quot;font-size: 150%;&quot;&gt;an error has occurred and email has been sent the administrator&lt;/b&gt;&lt;/div&gt;'
		);
	#
endif;

/* **********************************************************************
*	Framework_Database is a class created to manage database functions
*
*
*	The class manages all database interraction for the purpose of allowing certain things to be
*	turned on and off, as well as making development easier and more uniform.
*   An example would be Error Reporting.  Once the application is on the live
*	server, we can set $config-&gt;errors['display'] to false. Error reporting for database erros will not be shown.
*
*	This is real simple to use
*
*
*
*
******************************
**
**
**
**
**	Configuration ***
**		Scroll to the __construct method if you need to change which object
**		the database class uses for $config-&gt;connection and $config-&gt;errors
**
**
**
**
******************************
*
*	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;query($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;query($a);
*			$a = $db-&gt;fetch_object($a);
*			$a_rows = $db-&gt;num_rows();
*			echo $a_rows; // 2
*
*			while ($a_row = $db-&gt;fetch_object($a) ) :
*				$b = &quot;SELECT fieldA FROM tableA WHERE fieldA = {$a_row-&gt;fieldA}&quot;; // would return 6 rows
*				$b = $db-&gt;fetch_object($b);
*				$b_rows = $db-&gt;num_rows();
*					echo $b_rows; // 6
*				while ( $b_row = $db-&gt;fetch_object($b)) :
*					echo $b_row-&gt;fieldA;
*				endwhile;
*			endwhile;
*
*
********************
*
*
*		Results as Object:
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
*			$sql = $db-&gt;query($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;query($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 mysql_result() method rather than the more inefficient mysql_fetch_row() )
*
*		Specify the field's position in the Result Set
*			$sql = &quot;SELECT fieldA, fieldB FROM tableA&quot;;
*			$val = $db-&gt;fetch_row(1);        // would return fieldB's value
*
*		Specify the field name specifically
*			$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';
*
* 		Example with foreach loop:
*			foreach ($results as $key=&gt;$result) :
*				echo $result['fieldA'].'&lt;br /&gt;'.$results['fieldB'];
*			endforeach;
*
*
********************************************************************** */

class Framework_Database {

	# set whether errors should be displayed or not
	# probably want to turn off once site is live
	var $connect_type  = 'mysql';
	var $sql_txt       = '';
	var $config;

	/* ****************************************************************
	*
	* __construct
	*
	**************************************************************** */
	function __construct() {
		$this-&gt;config = (object) array();

		# ####
		#
		# $config object:
		# 	To make it easier to change which object is used for
		# 	connection and error configuration, we'll set it here
		#
		# Change $config to whatever is used for configuration settings
		#
			global $config;
			$this-&gt;config-&gt;errors = $config-&gt;errors;
			$this-&gt;config-&gt;db     = $config-&gt;db;
		# END
		#
		# ####
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Establish connection to the database
	* Be sure to set the connection info above
	*
	**************************************************************** */
	function connect() {
		global $config,$db;

			if ( !empty($config-&gt;db['db_name']) ) :

				#
				# try the connection
				$this-&gt;db_link = mysql_connect($config-&gt;db['host'], $config-&gt;db['user'], $config-&gt;db['password']);

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

				# The connection is good so lets get the Application Config Settings
				# and create the $config object
				else :
					$db_selected = mysql_select_db($config-&gt;db['db_name']);

				endif;

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

	/* ****************************************************************
	*
	* Generates a random ID for the $sql object.
	* This allows nested query output
	*
	**************************************************************** */
	function sqlId() {
		$id = rand();
		$uniqueId[] = 'sql' . $id;
		$uniqueId[] = 'row' . $id;
		return $uniqueId;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Error
	* If @$config-&gt;errors['display'], print errors to screen
	* Else, we format the SQL and SQL error and email to
	*	$config-&gt;errors['email_to']
	*
	**************************************************************** */
	function error() {
		global $config, $__email;

		$display_error    = (bool) ( isset($config-&gt;errors['display']) &amp;&amp; @$config-&gt;errors['display'] );
		$has_error        = (bool) ( isset($this-&gt;error) &amp;&amp; !empty($this-&gt;error) );

		if ( @$display_error &amp;&amp; @$has_error ) :
			echo $this-&gt;error;

		else :

			# ####
			#
			# Error has occurred
			# Send an email if Display errors is turned off
			#
			if ( @$has_error ) :

				$site_domain = preg_replace(&quot;/^(.*\.)?([^.]*\..*)$/&quot;, &quot;$2&quot;, $_SERVER['HTTP_HOST']);
				# ####
				#
				# An error has occurred
				# Format the error email message so we can send it
				$vars['to']['email']   = $config-&gt;errors['email_to'];
				$vars['from']['email'] = 'no-reply@'.$site_domain;

				$vars['subject'] = 'Database Error Occurred ' . date('m-d-Y H:i:s');

				$sql_txt = nl2br($this-&gt;format_sql($this-&gt;sql_txt));
				$sql_txt = str_replace(&quot;\t&quot;,'&amp;nbsp;&amp;nbsp;', $sql_txt);

				$sql_err = nl2br($this-&gt;format_sql($this-&gt;error));
				$sql_err = str_replace(&quot;\t&quot;,'&amp;nbsp;&amp;nbsp;', $sql_err);

				$vars['message'] = &quot;&lt;p&gt;&lt;strong&gt;SQL Statement:&lt;/strong&gt;&lt;br /&gt;&quot;
								 . $sql_txt
								 . &quot;&lt;/p&gt;&quot;
								 . &quot;&lt;p&gt;&lt;strong&gt;Error Text:&lt;/strong&gt;&lt;br /&gt;&quot;
								 . $sql_err
								 . &quot;&lt;/p&gt;&quot;;
				# END
				#
				# ####

				# ####
				#
				# Put together the email and send it
				$boundary = md5( uniqid ( rand() ) );

				$to_name    = (isset($vars['to']['name'])) ? $vars['to']['name'] : $vars['to']['email'];
				$to_email   = $vars['to']['email'];
				$from_name  = (isset($vars['from']['name'])) ? $vars['from']['name'] : $vars['from']['email'];
				$from_email = $vars['from']['email'];
				$replyto    = isset($vars['replyto']) ? $vars['replyto'] : $vars['from']['email'];
				$subject    = $vars['subject'];
				$message    = $vars['message'];

				$headers  = &quot;From: &quot;.$from_email.&quot;\n&quot;;
				if (!empty($replyto)) :
					$headers  .= &quot;Reply-To: &quot;.$replyto.&quot;\n&quot;;
				endif;
				$headers .= &quot;Received: \&quot;&quot;.$to_name.&quot;\&quot; &lt;&quot;.$to_email.&quot;&gt;\n&quot;;
				$headers .= &quot;MIME-Version: 1.0\n&quot;;
				$headers .= &quot;Subject: &quot;.$subject.&quot;\n&quot;;
				$headers .= &quot;Content-Type: multipart/related;&quot;;
				$headers .= &quot;boundary=\&quot;------------&quot;.$boundary.&quot;\&quot;\n&quot;;
				$headers .= &quot;This is a multi-part message in MIME format.\n&quot;;
				$headers .= &quot;--------------&quot;.$boundary.&quot;\n&quot;;
				$headers .= &quot;Content-Type: text/html; charset=ISO-8859-1\n&quot;;
				$headers .= &quot;Content-Transfer-Encoding: 7bit&quot;;

				mail($to_email, $subject, $message, $headers);
				# END
				#
				# ####
			endif;

		endif;
		$this-&gt;error='';
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Formats the SQL Statement. Hand for screen print
	* Mainly used for the error email, to make it more readable
	*
	**************************************************************** */
	function format_sql( $sql ) {

		$reserved_words = array(
			&quot;/SELECT/&quot;,
			&quot;/FROM/&quot;,
			&quot;/WHERE/&quot;,
			&quot;/CONCAT/&quot;,
			&quot;/INNER /&quot;,
			&quot;/ JOIN/&quot;,
			&quot;/LEFT /&quot;,
			&quot;/RIGHT /&quot;,
			&quot;/MATCH/&quot;,
			&quot;/AGAINST/&quot;,
			&quot;/AND/&quot;,
			&quot;/ORDER BY/&quot;,
			&quot;/ OR /&quot;,
			&quot;/ASC/&quot;,
			&quot;/DESC/&quot;,
			&quot;/LIMIT/&quot;,
			&quot;/ IN /&quot;,
			&quot;/SUM/&quot;,
			&quot;/GROUP BY/&quot;,
			&quot;/GROUP_/&quot;,
			&quot;/SEPARATOR/&quot;
		);

		$sql_err = '';
		$sql_txt = $sql;
		if ( strstr($sql, 'Query: ') ) :
			$sql = explode('Query: ', $sql);
			$sql_err = $sql[0];
			$sql_txt = $sql[1];
		endif;

		$sql_txt = preg_replace($reserved_words, &quot;&lt;span class=\&quot;reserved_word\&quot; style=\&quot;color: #3f97c6!important; font-weight: bold!important;\&quot;&gt;$0&lt;/span&gt;&quot;, $sql_txt);
		return $sql_err.$sql_txt;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

	/* ****************************************************************
	*
	* Run the query
	*
	**************************************************************** */
	function query( $sql='' ) {

		## keep the string value of the SQL statement in case of error
		$this-&gt;sql_txt = $sql;

		if ( $this-&gt;connect_type == 'mysql' ) :
			$this-&gt;result=mysql_query( $sql );

			if ( !$this-&gt;result ) :
				$this-&gt;error = mysql_error() . '&lt;br /&gt;Query: '.$sql;
				$this-&gt;error();
				$this-&gt;result = false;
			endif;

		else :
			$result = mysqli_query( $this-&gt;db_link, $sql );
			$this-&gt;result = $result;

			if ( !$this-&gt;result ) :
				$this-&gt;error = mysqli_error($this-&gt;db_link) . '&lt;br /&gt;Query: '.$sql;
				$this-&gt;error();
				$this-&gt;result = false;
			endif;

		endif;

		return $this-&gt;result;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

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

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

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

		## keep the string value of the SQL statement in case of error
		$this-&gt;sql_txt = $sql;

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

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

		if ( !$this-&gt;result ) :
			$this-&gt;error = mysql_error() . '&lt;br /&gt;Query: '.$sql;
			$this-&gt;error();
		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;query($sql);
	*
	*	while ($row = $db-&gt;fetch_object($sql) ) :
	*		echo $row-&gt;fieldA . ': ' . $row-&gt;fieldB;
	*	endwhile;
	*
	**************************************************************** */
	function fetch_object( $sql ) {
		if ( @$this-&gt;result ) :
			$uniqueIdentifier=rand();
			if ( $this-&gt;connect_type == 'mysql' ) :
				$$uniqueIdentifier=mysql_fetch_object( $sql );
			else :
				$$uniqueIdentifier=mysql_fetch_object( $sql );
			endif;
			return $$uniqueIdentifier;
			unset( $$uniqueIdentifier );
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

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

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

	/* ****************************************************************
	*
	* Returns the number of rows affected by a query
	*
	**************************************************************** */
	function rows_affected($result='') {
		if ( @$this-&gt;result ) :
			$uniqueIdentifier=rand();
			if (empty($result)) $result = $this-&gt;result;
			$$uniqueIdentifier = mysql_rows_affected( $result );
			return $$uniqueIdentifier;
			unset( $$uniqueIdentifier );
		else :
			return 0;
		endif;
	}
	/* ****************************************************************
	* 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';
	*
	* Example with foreach loop:
	*	foreach ($results as $key=&gt;$result) :
	*		echo $result['fieldA'].'&lt;br /&gt;'.$results['fieldB'];
	*	endforeach;
	*
	**************************************************************** */
	function to_array ( $sql='' ) {

		## keep the string value of the SQL statement in case of error
		$this-&gt;sql_txt = $sql;

		$i=0;
		$ret = array();
		$sql = $this-&gt;query($sql);
		if ( $this-&gt;connect_type == 'mysql' ) :
			if ( $sql ) :
				while ($row = mysql_fetch_assoc( $sql )) :
					for ($a=0; $a &lt; count($row); $a++) :
						$ret[$i] = $row;
					endfor;
					$i++;
				endwhile;
			endif;
		else :
			if ( $sql ) :
				while ($row = mysqli_fetch_assoc( $sql )) :
					for ($a=0; $a &lt; count($row); $a++) :
						$ret[$i] = $row;
					endfor;
					$i++;
				endwhile;
			endif;
		endif;
		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() {
		if ($this-&gt;db_link) :
			mysql_close($this-&gt;db_link);
		endif;
	}
	/* ****************************************************************
	* end :::
	**************************************************************** */

}
/* *********************************************************************************
* END :::
********************************************************************************* */
$db = new Framework_Database;
$db-&gt;connect();
?&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/253/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery Accordian without plug-ins &amp; with a bit of design freedom</title>
		<link>http://jjis.me/a/209</link>
		<comments>http://jjis.me/a/209#comments</comments>
		<pubDate>Sun, 13 Jun 2010 14:47:40 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[jQuery & Javascript]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=209</guid>
		<description><![CDATA[So you have a design and you have decided you want to use a jQuery accordion. You start to layout your design and implement the accordion only to find out that your design is going to cause problems with the standard accordion plug-ins. The problem with the standard accordion is that they require the child [...]]]></description>
			<content:encoded><![CDATA[<p>So you have a design and you have decided you want to use a jQuery accordion. You start to layout your design and implement the accordion only to find out that your design is going to cause problems with the standard accordion plug-ins.</p>
<p>The problem with the standard accordion is that they require the child and header elements to be nested within a parent.</p>
<p><span id="more-209"></span></p>
<h2>Example:</h2>
<pre class="brush: xml; title: ; wrap-lines: false; notranslate">
&lt;div id=&quot;accordion-wrapper&quot;&gt;
     &lt;h1&gt;Clickable Header 1&lt;/h1&gt;
          &lt;p&gt;Collapsible child 1&lt;/p&gt;
     &lt;h1&gt;Clickable Header 2&lt;/h1&gt;
          &lt;p&gt;Collapsible child 2&lt;/p&gt;
     &lt;h1&gt;Clickable Header 3&lt;/h1&gt;
          &lt;p&gt;Collapsible child 3&lt;/p&gt;
&lt;/div&gt;
</pre>
<p>Where this limits us in our design is when we want to add some extra style to the accordion list. I tend to use lists when building a list. So, if we take the code above and wrap each header and collapsible child with an &lt;li&gt;, we would completely break the accordion.</p>
<h2>Let&#8217;s break it down</h2>
<p>The standard jQuery accordion would prohibit this because the layout would throw off the jQuery plugin. The plugins look at the wrapping element (in this case &#8220;accordion-wrapper&#8221;). It then finds all header (&lt;h1&gt;) elements and binds the click event. This click event finds the first occurrence of the collapsible element (&lt;p&gt;) and will either expand or collapse it depending on it&#8217;s current state.</p>
<h2>Let&#8217;s fix this</h2>
<p>With the following script, you simply specify what the header class is going to be and what the collapsible class is going to be. What this allows us to do is place our accordion headers and collapsible elements within structured list, thus allowing more design/layout freedom.</p>
<h2>Example:</h2>
<pre class="brush: xml; title: ; wrap-lines: false; notranslate">
&lt;ul id=&quot;accordion-list&quot;&gt;
	&lt;li class=&quot;accordion-item&quot;&gt;
		&lt;h1 class=&quot;accordion-header&quot;&gt;Clickable Header 1&lt;/h1&gt;
		&lt;p&gt;Just placed here for an example of how we don't have our header and collapsible elements stacked&lt;/p&gt;
			&lt;ul class=&quot;accordion-collapsible&quot;&gt;
				&lt;li&gt;Collapsible child 1&lt;/li&gt;
				&lt;li&gt;Collapsible child 2&lt;/li&gt;
				&lt;li&gt;Collapsible child 3&lt;/li&gt;
				&lt;li&gt;Collapsible child 4&lt;/li&gt;
			&lt;/ul&gt;
	&lt;/li&gt;
	&lt;li class=&quot;accordion-item&quot;&gt;
		&lt;h1 class=&quot;accordion-header&quot;&gt;Clickable Header 2&lt;/h1&gt;
		&lt;p&gt;Just placed here for an example of how we don't have our header and collapsible elements stacked&lt;/p&gt;
			&lt;ul class=&quot;accordion-collapsible&quot;&gt;
				&lt;li&gt;Collapsible child 1&lt;/li&gt;
				&lt;li&gt;Collapsible child 2&lt;/li&gt;
				&lt;li&gt;Collapsible child 3&lt;/li&gt;
				&lt;li&gt;Collapsible child 4&lt;/li&gt;
			&lt;/ul&gt;
	&lt;/li&gt;
	&lt;li class=&quot;accordion-item&quot;&gt;
		&lt;h1 class=&quot;accordion-header&quot;&gt;Clickable Header 3&lt;/h1&gt;
		&lt;p&gt;Just placed here for an example of how we don't have our header and collapsible elements stacked&lt;/p&gt;
			&lt;ul class=&quot;accordion-collapsible&quot;&gt;
				&lt;li&gt;Collapsible child 1&lt;/li&gt;
				&lt;li&gt;Collapsible child 2&lt;/li&gt;
				&lt;li&gt;Collapsible child 3&lt;/li&gt;
				&lt;li&gt;Collapsible child 4&lt;/li&gt;
			&lt;/ul&gt;
	&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>&nbsp;</p>
<h2>The jQuery Code:</h2>
<pre class="brush: jscript; title: ; wrap-lines: false; notranslate">
$(document).ready(function() {
	/* ***
	* REQUIRED
	* set you classes accordingly below. */
	var accordion = {
		parent      : '.accordion-item',        // parent element containing the clickable header and collapsible
		header      : '.accordion-header',      // clickable header
		collapsible : '.accordion-collapsible'  // collapsible element
	};

	/* ***
	* hide all collapsible items */
	$(accordion.collapsible).css('display','none');

	/* ****
	* bind the accordion header click event */
	$(accordion.header).unbind('click');
	$(accordion.header).bind('click', function() {
		var header_obj      = $(this);          // The current header
		var next_parent_obj = $(this).parent(); // The parent of the header

		var content_obj = $(this).siblings(accordion.collapsible); // find the collapsible element

		if(content_obj.is(&quot;:hidden&quot;)) {
			// collapse all collapsible elements
			next_parent_obj.siblings(accordion.parent).each(function() {
				$(this).children(accordion.collapsible).slideUp('fast');
			});
			// show the content of the clicked header
			content_obj.slideDown('fast');
		} else {
			content_obj.slideUp('fast');
		}
	});
});
</pre>
<p>&nbsp;</p>
<h2>Seeing it in action</h2>
<p><span><br /></span></p>
<ul id="accordion-list">
<li class="accordion-item">
<h1 class="accordion-header">Clickable Header 1</h1>
<p>Just placed here for an example of how we don&#8217;t have our header and collapsible elements stacked</p>
<ul class="accordion-collapsible">
<li>Collapsible child 1</li>
<li>Collapsible child 2</li>
<li>Collapsible child 3</li>
<li>Collapsible child 4</li>
</ul>
</li>
<li class="accordion-item">
<h1 class="accordion-header">Clickable Header 2</h1>
<p>Just placed here for an example of how we don&#8217;t have our header and collapsible elements stacked</p>
<ul class="accordion-collapsible">
<li>Collapsible child 1</li>
<li>Collapsible child 2</li>
<li>Collapsible child 3</li>
<li>Collapsible child 4</li>
</ul>
</li>
<li class="accordion-item">
<h1 class="accordion-header">Clickable Header 3</h1>
<p>Just placed here for an example of how we don&#8217;t have our header and collapsible elements stacked</p>
<ul class="accordion-collapsible">
<li>Collapsible child 1</li>
<li>Collapsible child 2</li>
<li>Collapsible child 3</li>
<li>Collapsible child 4</li>
</ul>
</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/209/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>
		<item>
		<title>Load multiple JS files in one call</title>
		<link>http://jjis.me/a/94</link>
		<comments>http://jjis.me/a/94#comments</comments>
		<pubDate>Tue, 30 Mar 2010 21:44:34 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[jQuery & Javascript]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=94</guid>
		<description><![CDATA[With this script, you can easily load multiple JavaScript files in one call. The main purpose behind this is to simply cut down on the clutter in your source code. The function can be called from anywhere and the files are specified in an array]]></description>
			<content:encoded><![CDATA[<p>With this script, you can easily load multiple JavaScript files in one call. The main purpose behind this is to simply cut down on the clutter in your source code. </p>
<p>The function can be called from anywhere and the files are specified in an array</p>
<p><span id="more-94"></span></p>
<pre class="brush: jscript; title: ; wrap-lines: false; notranslate">
/* *********************************************************
*
* 	Setup a global config variable that
* 	stores all sitewide values such root
* 	url, absolute paths, Javascript library paths, etc.
*
********************************************************* */
	var config;
	config = {
		   URL : 'http://domain.com',
		   jsURL: &quot;http://domain.com/js&quot;
	};

/* **********************************************************************************************************
*
*	Function for looping through long lists of JS includes this function, when fed an array will
*	write the script tag to include the specified files as JS include files.
*
*	NOTE: This written to look in the 'js' folder under the site's root folder (http://domain.com/js/)
*
*	Directions:
*	config.loadComponents( { foldername:['filename.js'] } );
*
*	Example:
*	config.loadComponents( { jquery:['jquery-ui'] } );
*	OUTPUT: &lt;script src='http://domain.com/js/jquery/jquery-ui.js' type='text/javascript'&gt;&lt;/script&gt;
*
********************************************************************************************************** */
config.loadComponents = function (components) {
	for ( var key in components ) {
		var obj = components[key];
		for (var prop in obj) {
			var file = obj[prop];
			file = config.jsURL + '/' + key + &quot;/&quot; + file;
			document.write(unescape(&quot;%3Cscript src='&quot; + file + &quot;' type='text/javascript'%3E%3C/script%3E&quot;));
		}
	}
}

/* *********************************************************
*
*	Call the loadComponents() function
*	pay attention to how folder and file are called
*		folder: ['filename1.js', 'filename2.js']
*
********************************************************* */
config.loadComponents( {
	jquery:[
		'jquery-1.3.2.min.js',
		'jquery.easing.1.3.js',
	],
	app:[
		'app.js',
	],
	scripts:[
		'facbox.js'
	]
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/94/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery “characters remaining” script</title>
		<link>http://jjis.me/a/89</link>
		<comments>http://jjis.me/a/89#comments</comments>
		<pubDate>Tue, 30 Mar 2010 18:44:42 +0000</pubDate>
		<dc:creator>jj_jiles</dc:creator>
				<category><![CDATA[jQuery & Javascript]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://jjis.me/?p=89</guid>
		<description><![CDATA[This is a jQuery script for displaying &#8220;characters remaining&#8221; for input fields. It will look for any input element with the class &#8220;input&#8221; (or whatever you specify) and use the element&#8217;s maxlength attribute as the value to count against and update the &#8220;fieldName-counter&#8221; element. This is a very useful script for those occasions when you [...]]]></description>
			<content:encoded><![CDATA[<p>This is a jQuery script for displaying &#8220;characters remaining&#8221; for input fields.</p>
<p>It will look for any input element with the class &#8220;input&#8221; (or whatever you specify) and use the element&#8217;s maxlength attribute as the value to count against and update the &#8220;fieldName-counter&#8221; element.</p>
<p>This is a very useful script for those occasions when you want to limit the character entry for an input field.</p>
<p><span id="more-89"></span></p>
<pre class="brush: jscript; html-script: true; title: ; wrap-lines: false; notranslate">
&lt;!-- input and character count element --&gt;
    &lt;span id=&quot;fieldName-counter&quot;&gt;100&lt;/span&gt; characters remaining&lt;br /&gt;
    &lt;input type=&quot;text&quot; name=&quot;fieldName&quot; id=&quot;fieldName&quot; maxlength=&quot;100&quot; class=&quot;input&quot; /&gt;
&lt;!--/elements--&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
$(document).ready(function() {
    // change .input to desired class
    $('.input').each(function() {
        var inp = $(this);
        var maxlen =inp.attr('maxlength');
        if (maxlen &amp;gt; 0) {
            inp.bind('keyup', function(e) {
                len = new Number(inp.val().length);
                counter = maxlen-len;
                counterObj = '#' + inp.attr('id') + '-counter';
                $(counterObj).text(counter);
            });
        }
    });
});
&lt;/script&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://jjis.me/a/89/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

