<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Conditional Form Validation with Zend_Form</title>
	<atom:link href="http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/</link>
	<description>{web developer, entrepreneur }</description>
	<lastBuildDate>Mon, 15 Feb 2010 14:41:22 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Adamquadmon</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-428</link>
		<dc:creator>Adamquadmon</dc:creator>
		<pubDate>Mon, 15 Feb 2010 14:41:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-428</guid>
		<description>after a lot of tries I give up with this validator and simple put in the preValidation() method:

if ($data[&#039;datatype&#039;] == &#039;radio&#039;) {
	$this-&gt;option_1-&gt;setRequired(true);
}

where datatype is my parent field and radio is the value that need the check if child option_1 field value is not empty.

What do you think about?</description>
		<content:encoded><![CDATA[<p>after a lot of tries I give up with this validator and simple put in the preValidation() method:</p>
<p>if ($data['datatype'] == &#8216;radio&#8217;) {<br />
	$this-&gt;option_1-&gt;setRequired(true);<br />
}</p>
<p>where datatype is my parent field and radio is the value that need the check if child option_1 field value is not empty.</p>
<p>What do you think about?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeremy</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-277</link>
		<dc:creator>jeremy</dc:creator>
		<pubDate>Fri, 15 Jan 2010 11:41:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-277</guid>
		<description>Yeah, that allowEmpty can be a bear.  Glad to hear it&#039;s working for you.</description>
		<content:encoded><![CDATA[<p>Yeah, that allowEmpty can be a bear.  Glad to hear it&#8217;s working for you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neil</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-276</link>
		<dc:creator>Neil</dc:creator>
		<pubDate>Fri, 15 Jan 2010 08:49:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-276</guid>
		<description>Great Script.
Thanks
Had a bit of trouble with it at first as I hadn&#039;t read the write up properly and missed the bit about setting the allowEmpty flag on the validated element.  Very simple to use once this is in place.</description>
		<content:encoded><![CDATA[<p>Great Script.<br />
Thanks<br />
Had a bit of trouble with it at first as I hadn&#8217;t read the write up properly and missed the bit about setting the allowEmpty flag on the validated element.  Very simple to use once this is in place.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: omar</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-102</link>
		<dc:creator>omar</dc:creator>
		<pubDate>Tue, 13 Oct 2009 14:36:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-102</guid>
		<description>The problem i had was that my custom validator was not being called when the value of the input (select) was empty. I couldnt use setRequired() because in some cases (dependent upon another form value) i want to process empty values.
The solution was to do the following:

$organiser_member = new Zend_Form_Element_Text(&#039;organiser_member&#039;);
$organiser_member-&gt;setLabel(&#039;* Organiser:&#039;);
	        
// Force empty values through the custom validator!
$organiser_member-&gt;setRequired(false);
$organiser_member-&gt;setAllowEmpty(false);

// Add the custom validator
$organiser_member-&gt;addPrefixPath(&#039;BC_Validate&#039;, &#039;BC/Validate&#039;, &#039;validate&#039;);
$organiser_member-&gt;addValidator(&#039;EventOrganiser&#039;, false);
$form-&gt;addElement($organiser_member);

Now the custom validator is always called, whether the input &#039;organiser_member&#039; is set or not.</description>
		<content:encoded><![CDATA[<p>The problem i had was that my custom validator was not being called when the value of the input (select) was empty. I couldnt use setRequired() because in some cases (dependent upon another form value) i want to process empty values.<br />
The solution was to do the following:</p>
<p>$organiser_member = new Zend_Form_Element_Text(&#8217;organiser_member&#8217;);<br />
$organiser_member-&gt;setLabel(&#8217;* Organiser:&#8217;);</p>
<p>// Force empty values through the custom validator!<br />
$organiser_member-&gt;setRequired(false);<br />
$organiser_member-&gt;setAllowEmpty(false);</p>
<p>// Add the custom validator<br />
$organiser_member-&gt;addPrefixPath(&#8217;BC_Validate&#8217;, &#8216;BC/Validate&#8217;, &#8216;validate&#8217;);<br />
$organiser_member-&gt;addValidator(&#8217;EventOrganiser&#8217;, false);<br />
$form-&gt;addElement($organiser_member);</p>
<p>Now the custom validator is always called, whether the input &#8216;organiser_member&#8217; is set or not.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-100</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Mon, 14 Sep 2009 21:57:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-100</guid>
		<description>Another way to solve this problem is oveload method Zend_Form::isValid for example:
public function isValid($data)
    {
        // First validation
        $result = parent::isValid($data);
        
        // Add optional second validator if first pass form is ok
        if ($result == true and $this-&gt;getValue(&#039;type&#039;)==&#039;MEM&#039;) {
            $element = $this-&gt;getElement(&#039;type&#039;);
            $element-&gt;addValidator(new Zend_Validate_Date());
            $result = parent::isValid($data);
        }
        
        return $result;
    }</description>
		<content:encoded><![CDATA[<p>Another way to solve this problem is oveload method Zend_Form::isValid for example:<br />
public function isValid($data)<br />
    {<br />
        // First validation<br />
        $result = parent::isValid($data);</p>
<p>        // Add optional second validator if first pass form is ok<br />
        if ($result == true and $this-&gt;getValue(&#8217;type&#8217;)==&#8217;MEM&#8217;) {<br />
            $element = $this-&gt;getElement(&#8217;type&#8217;);<br />
            $element-&gt;addValidator(new Zend_Validate_Date());<br />
            $result = parent::isValid($data);<br />
        }</p>
<p>        return $result;<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Phil</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-98</link>
		<dc:creator>Phil</dc:creator>
		<pubDate>Tue, 21 Jul 2009 23:01:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-98</guid>
		<description>I want something exactly like this, but I don&#039;t think I&#039;ll be able to use yours. It seems to implement the letter of Zend_Validate_Interface, but not the spirit. ZVI requires the function isValid($value). You implemented that with isValid($value, $context=null). It technically implements the interface, but whenever you call that function with a null context, it errors out. So you can&#039;t use this with something like Zend_Filter_Input that hides the isValid call from you.</description>
		<content:encoded><![CDATA[<p>I want something exactly like this, but I don&#8217;t think I&#8217;ll be able to use yours. It seems to implement the letter of Zend_Validate_Interface, but not the spirit. ZVI requires the function isValid($value). You implemented that with isValid($value, $context=null). It technically implements the interface, but whenever you call that function with a null context, it errors out. So you can&#8217;t use this with something like Zend_Filter_Input that hides the isValid call from you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lauxa</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-93</link>
		<dc:creator>Lauxa</dc:creator>
		<pubDate>Thu, 18 Jun 2009 12:27:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-93</guid>
		<description>My situation is a little different because the customer wants to be able to change validators field by field at runtime.  I wrote a &quot;Not Duplicate&quot; custom validator that depends on a form_fieldDuplicate() routine being in the model.  To do conditional validators I&#039;ll either have to hard code this validator or set up a way to select the parent field, perhaps in a dropdown.  Either way, thanks for the article.</description>
		<content:encoded><![CDATA[<p>My situation is a little different because the customer wants to be able to change validators field by field at runtime.  I wrote a &#8220;Not Duplicate&#8221; custom validator that depends on a form_fieldDuplicate() routine being in the model.  To do conditional validators I&#8217;ll either have to hard code this validator or set up a way to select the parent field, perhaps in a dropdown.  Either way, thanks for the article.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: How to Get Six Pack Fast</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-87</link>
		<dc:creator>How to Get Six Pack Fast</dc:creator>
		<pubDate>Wed, 15 Apr 2009 16:38:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-87</guid>
		<description>I can tell that this is not the first time at all that you write about the topic. Why have you chosen it again?</description>
		<content:encoded><![CDATA[<p>I can tell that this is not the first time at all that you write about the topic. Why have you chosen it again?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jeremy</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-36</link>
		<dc:creator>jeremy</dc:creator>
		<pubDate>Mon, 19 Jan 2009 13:15:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-36</guid>
		<description>@Andreas I&#039;ve never dealt with that before, so I don&#039;t have a good answer for you.  I suggest heading over to &lt;a href=&quot;http://http://www.nabble.com/Zend-Framework-Community-f16154.html&quot; rel=&quot;nofollow&quot;&gt;Nabble&lt;/a&gt; and asking the ZF community for some recommendations.</description>
		<content:encoded><![CDATA[<p>@Andreas I&#8217;ve never dealt with that before, so I don&#8217;t have a good answer for you.  I suggest heading over to <a href="http://http://www.nabble.com/Zend-Framework-Community-f16154.html" rel="nofollow">Nabble</a> and asking the ZF community for some recommendations.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andreas~</title>
		<link>http://www.jeremykendall.net/2008/12/24/conditional-form-validation-with-zend_form/comment-page-1/#comment-35</link>
		<dc:creator>Andreas~</dc:creator>
		<pubDate>Mon, 19 Jan 2009 13:04:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.jeremykendall.net/?p=128#comment-35</guid>
		<description>Hey all,

thanks for that nice validator I was looking longtime for. Great job. I have one more question: If i try to use it for an file_upload element. It does not work. The Problem ist that the $context is null. so that there is no array where you can check if the contextkey is in. If I send a file -&gt; the $context is the well known $file array.... So till now I could not realize to find this solution above if a file upload is required when the radio button is set to &quot;Upload a File&quot;. Any Ideas? Especially i found out that the isValid method is not started when no file is choosen. Thanks for some comments :) A~</description>
		<content:encoded><![CDATA[<p>Hey all,</p>
<p>thanks for that nice validator I was looking longtime for. Great job. I have one more question: If i try to use it for an file_upload element. It does not work. The Problem ist that the $context is null. so that there is no array where you can check if the contextkey is in. If I send a file -&gt; the $context is the well known $file array&#8230;. So till now I could not realize to find this solution above if a file upload is required when the radio button is set to &#8220;Upload a File&#8221;. Any Ideas? Especially i found out that the isValid method is not started when no file is choosen. Thanks for some comments <img src='http://www.jeremykendall.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  A~</p>
]]></content:encoded>
	</item>
</channel>
</rss>
