<?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>measurement &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/measurement/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>How to Setup Different Error Messages for Each Zend Form Element Validator</title>
		<link>/2011/11/23/how-to-setup-different-error-messages-for-each-zend-form-element-validator/</link>
		<comments>/2011/11/23/how-to-setup-different-error-messages-for-each-zend-form-element-validator/#comments</comments>
		<pubDate>Wed, 23 Nov 2011 08:25:07 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[0]]></category>
		<category><![CDATA[Elementary arithmetic]]></category>
		<category><![CDATA[Error message]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[Nothing]]></category>
		<category><![CDATA[Numbers]]></category>
		<category><![CDATA[Pi]]></category>

		<guid isPermaLink="false">/?p=2469</guid>
		<description><![CDATA[Anyone who has worked with that has come across this problem. I&#8217;d like to show different error message on each validator attached to a Zend_Form_Element. Let&#8217;s say we validate an text input field. We want it to contain only digits, but also we&#8217;d like to display different messages when the field is empty and when &#8230; <a href="/2011/11/23/how-to-setup-different-error-messages-for-each-zend-form-element-validator/" class="more-link">Continue reading <span class="screen-reader-text">How to Setup Different Error Messages for Each Zend Form Element Validator</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/07/07/default-error-handling-in-zend-framework/" rel="bookmark" title="Default Error Handling in Zend Framework">Default Error Handling in Zend Framework </a></li>
<li><a href="/2010/06/04/one-form-multiple-db-records/" rel="bookmark" title="One Form &#8211; Multiple DB Records">One Form &#8211; Multiple DB Records </a></li>
<li><a href="/2010/04/09/secure-forms-with-zend-framework/" rel="bookmark" title="Secure Forms with Zend Framework">Secure Forms with Zend Framework </a></li>
<li><a href="/2010/07/22/zend_validate_db_recordexists-in-zend-framework-1-10/" rel="bookmark" title="Zend_Validate_Db_RecordExists in Zend Framework 1.10+">Zend_Validate_Db_RecordExists in Zend Framework 1.10+ </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Anyone who has worked with that has come across this problem. I&#8217;d like to show different error message on each validator attached to a <a href="http://framework.zend.com/manual/1.11/en/zend.form.standardElements.html" title="Zend Framework: Standard Form Elements" target="_blank">Zend_Form_Element</a>. Let&#8217;s say we validate an text input field. We want it to contain only digits, but also we&#8217;d like to display different messages when the field is empty and when the user has entered something that is different from digits. </p>
<p>It can be done by attaching to the form element two validators: <a href="http://framework.zend.com/manual/en/zend.validate.set.html#zend.validate.set.digits" title="Zend Framework: Standard Validation Classes, Zend_Validate_Digits" target="_blank">Zend_Validate_Digits</a> and <a href="http://framework.zend.com/manual/en/zend.validate.set.html#zend.validate.set.notempty" title="Zend Framework: Standard Validation Classes, Zend_Validate_NotEmpty" target="_blank">Zend_Validate_NotEmpty</a>, but first let&#8217;s see how to change the default &#8220;Value is required and can&#8217;t be empty&#8221; error message of a form field.</p>
<pre lang="PHP">
$element = $form->createElement('text', 'phone');
$element->setLabel('Please, enter your phone number:')
	->setRequired(true)
	->addValidator('Digits');
$form->addElement($element);
</pre>
<p>Here we validate the field with Zend_Validate_Digits and we have set it to be required. Thus everything containing characters, i.e. &#8220;my123name&#8221; or &#8220;007bond&#8221;, will be false, while &#8220;1234&#8221; will be true.</p>
<p><figure id="attachment_2485" style="width: 620px" class="wp-caption alignnone"><a href="/category/zend-framework-on-stoimen-com/"><img src="/wp-content/uploads/2011/11/zend-framework-logo.png" alt="Zend Framework" title="zend-framework-logo" width="620" height="169" class="size-full wp-image-2485" /></a><figcaption class="wp-caption-text">To show different error messages you&#039;ve to attach them per validator and not per form element!</figcaption></figure><br />
 <span id="more-2469"></span><br />
First of all this field is set to be required with the line ->setRequired(true), so we cannot submit the form if the input is empty and we&#8217;ll receive the default error message &#8220;Value is required and can&#8217;t be empty&#8221;. The question is how to change this default message, because as you know sometimes you&#8217;d like to say something different to your users or you&#8217;d like to display error messages on a language different from English. Here&#8217;s how.</p>
<pre lang="PHP">
$element = $form->createElement('text', 'phone');
$element->setLabel('Please, enter your phone number:')
	->setRequired(true)
	->addValidator('Digits')
	->addErrorMessage('Please, type your phone here!');
$form->addElement($element);
</pre>
<p>Now the error message is changed from &#8220;Value is required and can&#8217;t be empty&#8221; to &#8220;Please, type your phone here!&#8221;. </p>
<p>The problem is that when you add more than one validator to a form field you can still show one message regardless of the validator that has failed.</p>
<pre lang="PHP">
$element = $form->createElement('text', 'phone');
$element->setLabel('Please, enter your phone number:')
	->setRequired(true)
	->addValidator('NotEmpty', true)
	->addValidator('Digits', true)
	->addErrorMessage('Please, type your phone here!');
$form->addElement($element);
</pre>
<p>In this case whenever the field is empty or it contains something different from digits, the message shown to the user will be &#8220;Please, type your phone here!&#8221;. The question is can we show different error messages on every validator. This should look something like &#8220;The field cannot be empty!&#8221; when the field is empty and &#8220;Please, enter only digits!&#8221; when the user has entered something into the field, but it doesn&#8217;t contain only digits.</p>
<h2>The Solution</h2>
<p>Actually we have to attach error messages <em><strong>per validator</strong></em>, and not on a form element. Here&#8217;s how it can be done.</p>
<pre lang="PHP">
$notEmpty = new Zend_Validate_NotEmpty();
$notEmpty->setMessage('The field cannot be empty!');

$digits = new Zend_Validate_Digits();
$digits->setMessage('Please, enter only digits');

$element = $form->createElement('text', 'phone');
$element->setLabel('Please, enter your phone:')
	->setRequired(true)
	->addValidator($notEmpty, true)
	->addValidator($digits, true);
$form->addElement($element);
</pre>
<p>Note that we set to &#8220;true&#8221; the second parameter of addValidator. This is important because this way we break the validator&#8217;s chain and when the validation fails on NotEmpty the framework stops the validation of that field against the other validators.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/07/07/default-error-handling-in-zend-framework/" rel="bookmark" title="Default Error Handling in Zend Framework">Default Error Handling in Zend Framework </a></li>
<li><a href="/2010/06/04/one-form-multiple-db-records/" rel="bookmark" title="One Form &#8211; Multiple DB Records">One Form &#8211; Multiple DB Records </a></li>
<li><a href="/2010/04/09/secure-forms-with-zend-framework/" rel="bookmark" title="Secure Forms with Zend Framework">Secure Forms with Zend Framework </a></li>
<li><a href="/2010/07/22/zend_validate_db_recordexists-in-zend-framework-1-10/" rel="bookmark" title="Zend_Validate_Db_RecordExists in Zend Framework 1.10+">Zend_Validate_Db_RecordExists in Zend Framework 1.10+ </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/11/23/how-to-setup-different-error-messages-for-each-zend-form-element-validator/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Speed Up the jQuery Code: Selectors&#8217; Cache</title>
		<link>/2010/06/19/speed-up-the-jquery-code-selectors-cache/</link>
		<comments>/2010/06/19/speed-up-the-jquery-code-selectors-cache/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 08:36:08 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[chart]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[measurement]]></category>
		<category><![CDATA[results]]></category>
		<category><![CDATA[selectors]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">/?p=1630</guid>
		<description><![CDATA[Short Experiment Here&#8217;s a short optimization of a small chunk of jQuery code. The experiment was to increment the number of DOM element access. In this case this was a change of the innerHTML property &#8211; using the $.html() method. I&#8217;ve measured the result with the console.time() method and thus I expect correct results for &#8230; <a href="/2010/06/19/speed-up-the-jquery-code-selectors-cache/" class="more-link">Continue reading <span class="screen-reader-text">Speed Up the jQuery Code: Selectors&#8217; Cache</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2009/11/04/jquery-css-selectors-change-one-or-more-css-properties/" rel="bookmark" title="jQuery CSS selectors. Change one or more CSS properties!">jQuery CSS selectors. Change one or more CSS properties! </a></li>
<li><a href="/2010/02/09/optimizing-openlayers-speed-up-markers-load-time/" rel="bookmark" title="Optimizing OpenLayers. Speed up markers load time!">Optimizing OpenLayers. Speed up markers load time! </a></li>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>Short Experiment</h2>
<p>Here&#8217;s a short optimization of a small chunk of jQuery code. The experiment was to increment the number of DOM element access. In this case this was a change of the innerHTML property &#8211; using the $.html() method.</p>
<p>I&#8217;ve measured the result with the console.time() method and thus I expect correct results for both cases. In the first case I directly call the jQuery selectors&#8217; html() method:</p>
<pre lang="javascript">
for (var i = 0; i < 10000; i++) {
    $('#container').html(i);
}
</pre>
<p>While in the second case I "cache" it before the loop:</p>
<pre lang="javascript">
var t = $('#container');
for (var i = 0; i < 10000; i++) {
    t.html(i);
}
</pre>
<p>and here's the full code in the first case:</p>
<pre lang="html4strict">
<html>
<head>
    <title>jQuery Cache</title>
</head>
<body>

<div id="container"></div>

<script src="/scripts/library.js"></script>
<script>

$(document).ready(function() {

    console.time('foo');
    for (var i = 0; i < 10000; i++) {
        $('#container').html(i);
    }
    console.timeEnd('foo');
});
</script>
</body>
</html>
</pre>
<h2>The Results</h2>
<p>As expected the second "cached" approach gave better results. With the increment of the iterations the second method began to be slightly better than the first one. That's not so much, but imagine you have more than one selector in the loop's body?</p>
<h3>Numbers:</h3>
<p><img src="/wp-content/uploads/2010/06/table.png" /><br />
Note that in the time is in ms, and, yes, this is not so much, but when you deal with large data and you've more than one selector in the loop's body, this can be critical!</p>
<h3>Graphics:</h3>
<p><img src="/wp-content/uploads/2010/06/chart.png" /></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2009/11/04/jquery-css-selectors-change-one-or-more-css-properties/" rel="bookmark" title="jQuery CSS selectors. Change one or more CSS properties!">jQuery CSS selectors. Change one or more CSS properties! </a></li>
<li><a href="/2010/02/09/optimizing-openlayers-speed-up-markers-load-time/" rel="bookmark" title="Optimizing OpenLayers. Speed up markers load time!">Optimizing OpenLayers. Speed up markers load time! </a></li>
<li><a href="/2010/02/02/firebugs-console-time-accuracy/" rel="bookmark" title="Firebug&#8217;s console.time() accuracy">Firebug&#8217;s console.time() accuracy </a></li>
<li><a href="/2010/06/24/zend-framework-inject-javascript-code-in-a-actionview/" rel="bookmark" title="Zend Framework: Inject JavaScript Code in a Action/View">Zend Framework: Inject JavaScript Code in a Action/View </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/19/speed-up-the-jquery-code-selectors-cache/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
