<?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>Connecting the dots... &#187; sfForm</title>
	<atom:link href="http://blog.rajatpandit.com/tag/sfform/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rajatpandit.com</link>
	<description>Thoughts on Web Development, Scalability and Application Architecture</description>
	<lastBuildDate>Mon, 19 Jul 2010 12:46:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Using sfValidatorCallback</title>
		<link>http://blog.rajatpandit.com/2010/01/01/using-sfvalidatorcallback/</link>
		<comments>http://blog.rajatpandit.com/2010/01/01/using-sfvalidatorcallback/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 13:22:42 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[forms]]></category>
		<category><![CDATA[sfCallbackValidator]]></category>
		<category><![CDATA[sfForm]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[validation]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=442</guid>
		<description><![CDATA[Writing this post down as a note to self about using sfValidatorCallback. Step 1: add the sfValidatorCallback to the widget public function configure() { $this-&#62;widgetSchema['my_field'] = new sfWidgetFormTextArea(array('required' =&#62; false)); // add the validator $this-&#62;validatorSchema['my_field'] = new sfValidatorCallback( array('callback' =&#62; array( array($this, 'my_valdiation_function') // if you write the function in the validator itself // array($this-&#62;getObject(), [...]]]></description>
			<content:encoded><![CDATA[<p>Writing this post down as a note to self about using  sfValidatorCallback.<br />
Step 1: add the sfValidatorCallback to the widget</p>
<pre class="brush: php;">
public function configure()
{
  $this-&gt;widgetSchema['my_field'] =
    new sfWidgetFormTextArea(array('required' =&gt; false));
  // add the validator
  $this-&gt;validatorSchema['my_field']   = new sfValidatorCallback(
      array('callback' =&gt; array(
          array($this, 'my_valdiation_function')   // if you write the function in the validator itself
          // array($this-&gt;getObject(), 'my_valdiation_function')   // or if you move it to your model object
        ))
    );
}
</pre>
<p>As you can see form the code, I have commented out a line, that&#8217;s if you think its a good idea to move the validator to the model. I am not sure if I buy that idea but this what I have seen some developers do. I guess it kinda depends on what they are after, I would rather keep it all together unless it has its value in being shared across other classes.</p>
<p>And finally the signature for actual callback function:</p>
<pre class="brush: php;">
public function my_valdiation_function($validator, $value) {
  if ($condition_is_satisfied) {
    return $value;
  } else {
    $message = 'message detailing reason for EPIC FAIL!';
    throw new sfValidatorError($validator, $message);
  }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/01/01/using-sfvalidatorcallback/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
