<?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>Jawad.pk &#187; sfCryptographp</title>
	<atom:link href="http://jawad.pk/blog/tag/sfcryptographp/feed/" rel="self" type="application/rss+xml" />
	<link>http://jawad.pk/blog</link>
	<description>WEB 2.0 / RIAs Expert.</description>
	<lastBuildDate>Tue, 06 Sep 2011 12:43:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using sfCryptographp with custom validation</title>
		<link>http://jawad.pk/blog/2008/07/18/using-sfcryptographp-with-custom-validation/</link>
		<comments>http://jawad.pk/blog/2008/07/18/using-sfcryptographp-with-custom-validation/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 21:11:14 +0000</pubDate>
		<dc:creator>Jawad Khan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[symfony]]></category>
		<category><![CDATA[sfCryptographp]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://itsjawad.wordpress.com/?p=12</guid>
		<description><![CDATA[Using sfCryptographp with custom validation.. I just had to use captcha with symfony, Symfony is a great MVC framework, but i really don&#8217;t like its default validation method, rather I like javascript validations, so that user don&#8217;t have to wait for the server response after missing just a text field. So, I put mostly fields [...]]]></description>
			<content:encoded><![CDATA[<p>Using sfCryptographp with custom validation..</p>
<p>I just had to use captcha with symfony, Symfony is a great MVC framework, but i really don&#8217;t like its default validation method, rather I like javascript validations, so that user don&#8217;t have to wait for the server response after missing just a text field. So, I put mostly fields checking validations with javascript and then check at the server for the specific fields which do require server response like checking username if its unique in the database. Such validations are also possible with the quick response using Ajax, but all we need to do is to avoid symfony&#8217;s default validation method in order to achieve that.</p>
<p>Now coming back to captcha, the php-captha is a great library for the normal php apps, It can also be used with symfony, but I gave preference to symfony&#8217;s already available pluggins..<br />
so here is the pluggin: sfCryptographp<br />
its installation is pretty straight forward.</p>
<p>$ symfony plugin-install http://plugins.symfony-project.com/sfCryptographpPlugin</p>
<p>After your done with installation, enable the crypt pluggin in your settings.yml file</p>
<p>like:</p>
<p>.settings:<br />
enabled_modules:        [default, cryptographp]</p>
<p>Now, Open your template file, add following line:<br />
&lt;?php use_helper(&#8216;Cryptographp&#8217;); ?&gt;</p>
<p>Now insert following code in anywhere within the form where you want captcha to be visible.</p>
<p>&lt;?php echo cryptographp_picture(); ?&gt;<br />
&lt;?php echo cryptographp_reload(); ?&gt;</p>
<p>&lt;?php echo input_tag(&#8216;captcha&#8217;); ?&gt;</p>
<p>It was pretty easy, now if u test your template you can see captcha images, The above code lines are same as described in sfCryptographp wiki page. Now for the validation we will not follow the wiki, we will put some logic at the actions file. before we do it we need little modification in sfCryptographpValidator class, which can be found at:</p>
<p>plugins\sfCryptographpPlugin\lib\validator\sfCryptographpValidator.class.php</p>
<p>open that class</p>
<p>add another function like:</p>
<p>public function checkCode($value)<br />
{<br />
if (chk_crypt($value)) {<br />
return true;<br />
} else {<br />
return false;<br />
}</p>
<p>}</p>
<p>Now goto your actions class, put the following code at the place where you are handling form post actions.</p>
<p>// create an instance from sfCryptographpValidator class<br />
// and use the new function to validate user entered text</p>
<p>$captcha = new sfCryptographpValidator();</p>
<p>if (!$captcha-&gt;checkCode($_POST['captcha']))<br />
{<br />
//user entered wrong code&#8230;<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://jawad.pk/blog/2008/07/18/using-sfcryptographp-with-custom-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

