<?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: On input validation 2</title>
	<atom:link href="http://naneau.nl/2007/05/19/on-input-validation-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://naneau.nl/2007/05/19/on-input-validation-2/</link>
	<description>Go dik-dik, go!</description>
	<lastBuildDate>Fri, 03 Sep 2010 14:00:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: M_flash</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-912</link>
		<dc:creator>M_flash</dc:creator>
		<pubDate>Wed, 11 Jul 2007 20:09:00 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-912</guid>
		<description>Hey Naneau!

Thank you for your help on zftalk! I&#039;ve gotten started and really love this approach. 

I&#039;ve worked to avoid the double submit issue and I just wanted to share my approach that seems to work:

* Javascript part in formvalidation.js*
submit: function(e) {
        Event.stop(e);
        //stop the submit

		var test = $$(&#039;#&#039; + this.form.id);
		
        var el = $$(&#039;#&#039; + this.form.id + &#039; input.submit&#039;);
        if (el) {
            el[0].spinBeside(&#039;Validating&#039;, this.form.id);
            el[0].disabled = true; // Simple stopping of double submitting
        }

        this.doRequest(this.validateUrl + &#039;form/form/&#039; + this.type, true);
    },

** And this part is in the onComplete function after failure is set to halt after token error - see below **
            	if (!data.messages &amp;&amp; data.token_error)
                	{
			           var html = &#039;Critical error: &#039; + data.token_error;
			           html += &#039;&#039;;

						el[0].value = &quot;X&quot;;
						el[0].disabled = true;
			            el[0].addClassName(&#039;error&#039;);
			            new Insertion.After(el[0], html);
                	}
* Server part (see http://phpsecurity.org/ch02.pdf page 27) *
*- index.php -*
if (isset($_POST) &amp;&amp; $_POST != array())
{
	if (!isset($_SESSION[&#039;token&#039;]) 
	&#124;&#124; $_POST[&#039;token&#039;] != $_SESSION[&#039;token&#039;])
	{
		die(&quot;{&#039;sucess&#039;: false, &#039;token_error&#039;: &#039;Invalid token - either you have submitted the form twice or you are an unauthorised user. Please contact admin if this is not correct.&#039;}&quot;);
	}
	
	$token_age = time() - $_SESSION[&#039;token_time&#039;];
	$max_token_age = 60*60*3;
	if ($token_age &gt; $max_token_age)
	{
		die(&quot;{sucess: false; &#039;token_error&#039;: &#039;Token timeout - you have been away for to long, form invalid.&#039;}&quot;);
	}
}

$token = md5(uniqid(rand(), TRUE));
$_SESSION[&#039;token&#039;] = $token;
$_SESSION[&#039;token_time&#039;] = time();

*- FormValidateController.php -*
	protected function sendJsonResponse($return){
		// Reset token since AJAX causes multiple calls with the same SESSION token
		$_SESSION[&quot;token&quot;] = $_POST[&quot;token&quot;];
		echo (Zend_Json::encode($return));
		die();
	}</description>
		<content:encoded><![CDATA[<p>Hey Naneau!</p>
<p>Thank you for your help on zftalk! I&#8217;ve gotten started and really love this approach. </p>
<p>I&#8217;ve worked to avoid the double submit issue and I just wanted to share my approach that seems to work:</p>
<p>* Javascript part in formvalidation.js*<br />
submit: function(e) {<br />
        Event.stop(e);<br />
        //stop the submit</p>
<p>		var test = $$(&#8216;#&#8217; + this.form.id);</p>
<p>        var el = $$(&#8216;#&#8217; + this.form.id + &#8216; input.submit&#8217;);<br />
        if (el) {<br />
            el[0].spinBeside(&#8216;Validating&#8217;, this.form.id);<br />
            el[0].disabled = true; // Simple stopping of double submitting<br />
        }</p>
<p>        this.doRequest(this.validateUrl + &#8216;form/form/&#8217; + this.type, true);<br />
    },</p>
<p>** And this part is in the onComplete function after failure is set to halt after token error &#8211; see below **<br />
            	if (!data.messages &amp;&amp; data.token_error)<br />
                	{<br />
			           var html = &#8216;Critical error: &#8216; + data.token_error;<br />
			           html += &#8221;;</p>
<p>						el[0].value = &#8220;X&#8221;;<br />
						el[0].disabled = true;<br />
			            el[0].addClassName(&#8216;error&#8217;);<br />
			            new Insertion.After(el[0], html);<br />
                	}<br />
* Server part (see <a href="http://phpsecurity.org/ch02.pdf" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/phpsecurity.org/ch02.pdf?referer=');">http://phpsecurity.org/ch02.pdf</a> page 27) *<br />
*- index.php -*<br />
if (isset($_POST) &amp;&amp; $_POST != array())<br />
{<br />
	if (!isset($_SESSION['token'])<br />
	|| $_POST['token'] != $_SESSION['token'])<br />
	{<br />
		die(&#8220;{&#8217;sucess&#8217;: false, &#8216;token_error&#8217;: &#8216;Invalid token &#8211; either you have submitted the form twice or you are an unauthorised user. Please contact admin if this is not correct.&#8217;}&#8221;);<br />
	}</p>
<p>	$token_age = time() &#8211; $_SESSION['token_time'];<br />
	$max_token_age = 60*60*3;<br />
	if ($token_age &gt; $max_token_age)<br />
	{<br />
		die(&#8220;{sucess: false; &#8216;token_error&#8217;: &#8216;Token timeout &#8211; you have been away for to long, form invalid.&#8217;}&#8221;);<br />
	}<br />
}</p>
<p>$token = md5(uniqid(rand(), TRUE));<br />
$_SESSION['token'] = $token;<br />
$_SESSION['token_time'] = time();</p>
<p>*- FormValidateController.php -*<br />
	protected function sendJsonResponse($return){<br />
		// Reset token since AJAX causes multiple calls with the same SESSION token<br />
		$_SESSION["token"] = $_POST["token"];<br />
		echo (Zend_Json::encode($return));<br />
		die();<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naneau</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-151</link>
		<dc:creator>Naneau</dc:creator>
		<pubDate>Tue, 22 May 2007 14:54:01 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-151</guid>
		<description>Yes, that is the basic flow. I haven&#039;t explained the javascript part in detail, but you did get the gist of it. I have a single controller (the url for which is in the forms.js file). The ajax request to that controller gets an argument which form it is (which the javascript gets out of the id of the form) and is therefore able to find a validator for it, and validate all fields. 

If the form is valid it does a &quot;real&quot; submit of the form. Because  you can&#039;t rely on JavaScript validation, you have to validate it again on the server after that submit. In the demo application you just get redirected back to the demo form, but in a real world scenario you would probably want to redirect to something useful, and alert the user that his data has been saved.

The someAction could just be any normal controller action where you would have the need for a form.</description>
		<content:encoded><![CDATA[<p>Yes, that is the basic flow. I haven&#8217;t explained the javascript part in detail, but you did get the gist of it. I have a single controller (the url for which is in the forms.js file). The ajax request to that controller gets an argument which form it is (which the javascript gets out of the id of the form) and is therefore able to find a validator for it, and validate all fields. </p>
<p>If the form is valid it does a &#8220;real&#8221; submit of the form. Because  you can&#8217;t rely on JavaScript validation, you have to validate it again on the server after that submit. In the demo application you just get redirected back to the demo form, but in a real world scenario you would probably want to redirect to something useful, and alert the user that his data has been saved.</p>
<p>The someAction could just be any normal controller action where you would have the need for a form.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dino</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-147</link>
		<dc:creator>dino</dc:creator>
		<pubDate>Tue, 22 May 2007 12:55:37 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-147</guid>
		<description>hey, so now I start^^
This is how i understood your way (the action names are copied from the example above)
someAction():
displays the form and includes http://naneau.nl/zf/js/application/formvalidator/forms.js

onSubmit() of the form:
ajax request to the url in the forms.js, the action should be formAction(), right?
This actions checks all values and validates them and send the json response

if the validation was successful, the javascript performs a page refresh to the someAction(); and validates it again (if the user doesn&#039;t allow js or something else) and then it performs the form :)

Hope i understood you well, else correct me :)</description>
		<content:encoded><![CDATA[<p>hey, so now I start^^<br />
This is how i understood your way (the action names are copied from the example above)<br />
someAction():<br />
displays the form and includes <a href="http://naneau.nl/zf/js/application/formvalidator/forms.js" rel="nofollow">http://naneau.nl/zf/js/application/formvalidator/forms.js</a></p>
<p>onSubmit() of the form:<br />
ajax request to the url in the forms.js, the action should be formAction(), right?<br />
This actions checks all values and validates them and send the json response</p>
<p>if the validation was successful, the javascript performs a page refresh to the someAction(); and validates it again (if the user doesn&#8217;t allow js or something else) and then it performs the form <img src='http://naneau.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Hope i understood you well, else correct me <img src='http://naneau.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naneau</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-141</link>
		<dc:creator>Naneau</dc:creator>
		<pubDate>Tue, 22 May 2007 02:14:55 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-141</guid>
		<description>The validator class is just an example of how you might do input validation. You should subclass it to create something usable, see the first code example in the post on how you should do that. Using it is something different. I tried to make it broadly applicable, you could just validate $_POST, but there&#039;s also a field-validating method. There are phpdoc-blocks for each method.

I found that I needed a concept of &#039;required&#039; fields. Those fields get checked no matter what, and will raise an error if they are empty(). Non-required fields will only get checked if they have contents. See the demo to get an idea of how that works.</description>
		<content:encoded><![CDATA[<p>The validator class is just an example of how you might do input validation. You should subclass it to create something usable, see the first code example in the post on how you should do that. Using it is something different. I tried to make it broadly applicable, you could just validate $_POST, but there&#8217;s also a field-validating method. There are phpdoc-blocks for each method.</p>
<p>I found that I needed a concept of &#8216;required&#8217; fields. Those fields get checked no matter what, and will raise an error if they are empty(). Non-required fields will only get checked if they have contents. See the demo to get an idea of how that works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dino</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-138</link>
		<dc:creator>dino</dc:creator>
		<pubDate>Mon, 21 May 2007 21:19:28 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-138</guid>
		<description>First of all, thank you. But I&#039;m not able to work with this example, I don&#039;t know exactly if it&#039;s just my tiredness or something else... :) So I will wait until you post the whole example with all files :) I&#039;m watching you :)

best regards</description>
		<content:encoded><![CDATA[<p>First of all, thank you. But I&#8217;m not able to work with this example, I don&#8217;t know exactly if it&#8217;s just my tiredness or something else&#8230; <img src='http://naneau.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  So I will wait until you post the whole example with all files <img src='http://naneau.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I&#8217;m watching you <img src='http://naneau.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>best regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naneau</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-137</link>
		<dc:creator>Naneau</dc:creator>
		<pubDate>Mon, 21 May 2007 18:58:59 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-137</guid>
		<description>I&#039;ve put it up, see the end of the post. I must warn you though, I have not tested it thoroughly.</description>
		<content:encoded><![CDATA[<p>I&#8217;ve put it up, see the end of the post. I must warn you though, I have not tested it thoroughly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dino</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-136</link>
		<dc:creator>dino</dc:creator>
		<pubDate>Mon, 21 May 2007 17:44:54 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-136</guid>
		<description>Okay, then I hope &quot;soon&quot; is really soon and not just in a few weeks :-)</description>
		<content:encoded><![CDATA[<p>Okay, then I hope &#8220;soon&#8221; is really soon and not just in a few weeks <img src='http://naneau.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naneau</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-135</link>
		<dc:creator>Naneau</dc:creator>
		<pubDate>Mon, 21 May 2007 16:17:34 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-135</guid>
		<description>I&#039;m working on a code browser for things like this, expect either that, or some kind of other download with this and other classes sometime soon...!

P.S. Thanks ;)</description>
		<content:encoded><![CDATA[<p>I&#8217;m working on a code browser for things like this, expect either that, or some kind of other download with this and other classes sometime soon&#8230;!</p>
<p>P.S. Thanks <img src='http://naneau.nl/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dino</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-134</link>
		<dc:creator>dino</dc:creator>
		<pubDate>Mon, 21 May 2007 14:38:22 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-134</guid>
		<description>Hi,

nice page! I think you&#039;re on a good way with this blog because you always post some nice hints how to work with the Zend Framework and other nice functions like the CSS Charts :-)
This topic over here looks also very interesting because there are a lot  of (older) solutions but they don&#039;t fit in the framework. But can you be so kind to post the whole example sourcecode? (for example the  Naneau_Validator_Abstract class).

Best regards,
dino</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>nice page! I think you&#8217;re on a good way with this blog because you always post some nice hints how to work with the Zend Framework and other nice functions like the CSS Charts <img src='http://naneau.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
This topic over here looks also very interesting because there are a lot  of (older) solutions but they don&#8217;t fit in the framework. But can you be so kind to post the whole example sourcecode? (for example the  Naneau_Validator_Abstract class).</p>
<p>Best regards,<br />
dino</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Naneau</title>
		<link>http://naneau.nl/2007/05/19/on-input-validation-2/comment-page-1/#comment-122</link>
		<dc:creator>Naneau</dc:creator>
		<pubDate>Sun, 20 May 2007 13:45:14 +0000</pubDate>
		<guid isPermaLink="false">http://naneau.nl/2007/05/19/on-input-validation-2/#comment-122</guid>
		<description>Interestingly enough, though totally unrelated, my javascript external link checker thinks that http://www.naneau.nl/ isn&#039;t the same thing as http://naneau.nl/ . I should fix that :) Even though I&#039;m opposed to adding the totally obsolete www part to my URIs if I can avoid it.</description>
		<content:encoded><![CDATA[<p>Interestingly enough, though totally unrelated, my javascript external link checker thinks that <a href="http://www.naneau.nl/" rel="nofollow" onclick="pageTracker._trackPageview('/outgoing/www.naneau.nl/?referer=');">http://www.naneau.nl/</a> isn&#8217;t the same thing as <a href="http://naneau.nl/" rel="nofollow">http://naneau.nl/</a> . I should fix that <img src='http://naneau.nl/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Even though I&#8217;m opposed to adding the totally obsolete www part to my URIs if I can avoid it.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
