<?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>Just a bunch of code &#187; valdate</title>
	<atom:link href="http://www.bunchacode.com/tag/valdate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bunchacode.com</link>
	<description></description>
	<lastBuildDate>Sun, 11 Sep 2011 19:56:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>jquery validate plugin with ajax duplicate check</title>
		<link>http://www.bunchacode.com/programming/jquery-validate-plugin-with-ajax-duplicate-check/</link>
		<comments>http://www.bunchacode.com/programming/jquery-validate-plugin-with-ajax-duplicate-check/#comments</comments>
		<pubDate>Thu, 24 Sep 2009 19:40:58 +0000</pubDate>
		<dc:creator>Funky Dude</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[valdate]]></category>

		<guid isPermaLink="false">http://www.bunchacode.com/?p=183</guid>
		<description><![CDATA[jQuery validate plugin is pretty awsome. However it doesn&#8217;t do everything. That&#8217;s why the plugin have the addMethod function. And I need to add an ajax duplicate check for an email input. Here&#8217;s the method i wrote. There might be a better way. I would love to know. 1 2 3 4 5 6 7 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" target="_blank">jQuery validate plugin</a> is pretty awsome. However it doesn&#8217;t do everything. That&#8217;s why the plugin have the addMethod function. And I need to add an ajax duplicate check for an email input. Here&#8217;s the method i wrote. There might be a better way. I would love to know.</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre>
<pre><span class="php">jQuery<span class="php-operator">.</span>validator<span class="php-operator">.</span>addMethod<span class="php-brackets">(</span><span class="php-string">&quot;checkForDupeEmail&quot;</span>, <span class="php-function">function</span><span class="php-brackets">(</span>value, element, param<span class="php-brackets">)</span><span class="php-brackets">{</span>

<span class="php-keyword">var</span> ajaxFunc <span class="php-operator">=</span> <span class="php-var">$</span><span class="php-operator">.</span>ajax<span class="php-brackets">(</span><span class="php-brackets">{</span>
async<span class="php-operator">:</span><span class="php-keyword">false</span>,   <span class="php-comment">//we have to set it to false, it does not return a value before we even complete the request.
</span>
data<span class="php-operator">:</span><span class="php-string">'email='</span><span class="php-operator">+</span><span class="php-brackets">(</span><span class="php-var">$</span><span class="php-operator">.</span><span class="php-function">trim</span><span class="php-brackets">(</span>value<span class="php-brackets">)</span><span class="php-brackets">)</span>,
type<span class="php-operator">:</span><span class="php-string">'POST'</span>,
url<span class="php-operator">:</span><span class="php-string">'/employees/ajax_checkDupe'</span>,
dataType<span class="php-operator">:</span><span class="php-string">'text'</span>,
<span class="php-brackets">}</span><span class="php-brackets">)</span>;

<span class="php-comment">//here we check the response
</span>

<span class="php-keyword">if</span><span class="php-brackets">(</span>ajaxFunc<span class="php-operator">.</span>responseText <span class="php-operator">=</span><span class="php-operator">=</span> <span class="php-number">1</span><span class="php-brackets">)</span>
<span class="php-keyword">return</span> <span class="php-keyword">true</span>;
<span class="php-keyword">else</span>
<span class="php-keyword">return</span> <span class="php-keyword">false</span>;
<span class="php-brackets">}</span><span class="php-brackets">)</span>;</span></pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.bunchacode.com/programming/jquery-validate-plugin-with-ajax-duplicate-check/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

