<?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>Kurinchi Blogger Scribbles ... &#187; multivalidatable behavior</title>
	<atom:link href="http://kurinchilamp.kurinchilion.com/tag/multivalidatable-behavior/feed" rel="self" type="application/rss+xml" />
	<link>http://kurinchilamp.kurinchilion.com</link>
	<description>On Open Source Technologies</description>
	<lastBuildDate>Mon, 02 Jan 2012 06:14:45 +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>CakePHP: Multi-validatable Behavior</title>
		<link>http://kurinchilamp.kurinchilion.com/2009/07/cakephp-multi-validatable-behavior.html</link>
		<comments>http://kurinchilamp.kurinchilion.com/2009/07/cakephp-multi-validatable-behavior.html#comments</comments>
		<pubDate>Tue, 21 Jul 2009 17:40:52 +0000</pubDate>
		<dc:creator>kurinchilamp</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cakePHP]]></category>
		<category><![CDATA[cakephp multiple validation]]></category>
		<category><![CDATA[multi-validatable]]></category>
		<category><![CDATA[multivalidatable]]></category>
		<category><![CDATA[multivalidatable behavior]]></category>

		<guid isPermaLink="false">http://kurinchilamp.kurinchilion.com/?p=512</guid>
		<description><![CDATA[Consider the following scenario where we have a database table:users and that we need carry the validations for the following forms i) Login ii) Change password iii) Add/Edit user records iv) Forgot password You can either write separate controllers and have each controller call a model based on table: users to validate each input field [...]]]></description>
			<content:encoded><![CDATA[<p>Consider the following scenario where we have a database table:users and that we need carry the validations for the following forms<br />
i) Login<br />
ii) Change password<br />
iii) Add/Edit user records<br />
iv) Forgot password </p>
<p>You can either write separate controllers and have each controller call a model based on <em>table: users </em>to validate each input field  or use the same user model to carry out different validations which sounds logical. </p>
<p>It is easy to carry out different validations in a cakephp model by using the <strong>Multi-validatable Behavior</strong> by having different validation sets for different testing conditions.</p>
<p><strong>Key things to note here &#8230;</strong></p>
<p>i) Download the code for <strong>Multivalidatable Behavior</strong> and have it placed under /models/behaviors/ folder</p>
<p>ii) In the model where you want to have multi validation, you need to include multivalidatable behavior like<br />
<strong>var $actsAs = array(&#8220;Multivalidatable&#8221;);</strong></p>
<p>iii) Add validation rulesets array like<br />
var $validationSets = array(&#8216;login&#8217; => array(&#8216;name&#8217;=>array(&#8216;rule&#8217;=>&#8217;alphanumeric&#8217;)),<br />
                                     &#8216;changepassword&#8217; => array(&#8216;password&#8217;=>array(&#8216;rule&#8217;=>&#8217;notEmpty&#8217;))<br />
);</p>
<p>iv) In the controller where you want to apply the validation rule set, you need to add the respective validation like</p>
<p>function login(){<br />
 $this->User->setValidation(&#8216;login&#8217;);<br />
}</p>
<p>function changepassword(){<br />
 $this->User->setValidation(&#8216;changepassword&#8217;);<br />
}</p>
<p>For more info visit <a href="http://bakery.cakephp.org/articles/view/multivalidatablebehavior-using-many-validation-rulesets-per-model" target="_blank">CakePHP Bakery</a></p>
]]></content:encoded>
			<wfw:commentRss>http://kurinchilamp.kurinchilion.com/2009/07/cakephp-multi-validatable-behavior.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

