<?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>Validators | Jörg Drzycimski</title>
	<atom:link href="https://drzycimski.com/tag/validators/feed/" rel="self" type="application/rss+xml" />
	<link>https://drzycimski.com/tag/validators/</link>
	<description></description>
	<lastBuildDate>Sun, 01 Oct 2017 16:51:28 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>No-MVC Zend Framework: Zend_Decorator and Zend_Validator</title>
		<link>https://drzycimski.com/programmierung/no-mvc-zend-framework-zend_decorator-and-zend_validator/</link>
					<comments>https://drzycimski.com/programmierung/no-mvc-zend-framework-zend_decorator-and-zend_validator/#respond</comments>
		
		<dc:creator><![CDATA[Jörg]]></dc:creator>
		<pubDate>Mon, 07 Feb 2011 18:20:51 +0000</pubDate>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[comment spam blocker]]></category>
		<category><![CDATA[Decorators]]></category>
		<category><![CDATA[spam filter]]></category>
		<category><![CDATA[Validators]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Form]]></category>
		<guid isPermaLink="false">http://www.drzycimski.com/?p=133</guid>

					<description><![CDATA[<p>In the last article, we have already set some basic decorators for Zend_Form. The next one is a decorator for the label, appending an asterisk (*) to labels of required fields, and display error messages below the label instead of the field. In your &#8222;Form&#8220; subfolder, create a folder &#8222;Decorator&#8220;, and in it, a file [&#8230;]</p>
<p>The post <a href="https://drzycimski.com/programmierung/no-mvc-zend-framework-zend_decorator-and-zend_validator/">No-MVC Zend Framework: Zend_Decorator and Zend_Validator</a> appeared first on <a href="https://drzycimski.com">Jörg Drzycimski</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>In the last article, we have already set some basic decorators for Zend_Form. The next one is a decorator for the label, appending an asterisk (*) to labels of required fields, and display error messages below the label instead of the field. In your &#8222;Form&#8220; subfolder, create a folder &#8222;Decorator&#8220;, and in it, a file named &#8222;Label.php&#8220;:</p>
<pre class="brush:php">class JD_Form_Decorator_Label extends Zend_Form_Decorator_Label
{
 public function getLabel()
 {
   $element = $this-&gt;getElement();
   $label = trim($element-&gt;getLabel());
   if ($element-&gt;isRequired()) {
     $label .= ' *';
   }
   $errors = $element-&gt;getMessages();
   if (empty($errors)) {
     $element-&gt;setLabel($label);
     return parent::getLabel();
   }
   $label .= '&lt;br /&gt;&lt;span style="color:red;font-size:0.8em"&gt;'
   . implode('&lt;br /&gt;', $errors)
   . '&lt;/span&gt;';
   $element-&gt;setLabel($label);
   return parent::getLabel();
 }
}</pre>
<p>The name &#8222;Label&#8220; corresponds to the settings for the ViewHelper in the decorators, and folder / name to the settings in the prefix path. Credits for this script, though, goes to <a title="Padraic Brady" href="http://blog.astrumfutura.com/" target="_blank" rel="noopener">Padraic Brady</a>, where one can get a lot of good ideas of how to solve ZF problems 😉</p>
<p>Zend Framework comes with a lot of smart validators to use with Zend_Form. But with my goal in mind to create a page comment plugin for the relaunch of <a title="surfspot.de" href="http://www.surfspot.de" target="_blank" rel="noopener">surfspot.de</a>, I needed a validator to check if the user input contains foul language&#8230; no point in people abusing each other in the anonymity of the Internet 😉 The old version of the site uses a validator, comparing user input to a string of bad bad words I don´t want to see on my site, so I needed to make that one &#8222;Zend_Form&#8220; compatible. Besides, over the years I added some of the most notorious spam words to the validator, so it acts as a low level spam filter as well&#8230; surfers just don´t need little blue pills to have some fun 😉</p>
<p>Anyway, create &#8222;JD/Form/Validator/Badwords.php&#8220;, and add the following lines:</p>
<pre class="brush:php">class JD_Form_Validator_Badwords extends Zend_Validate_Abstract
{
 /**
 * Validation failure message key for when the value contains foul language
 */
 const BAD_WORDS = 'badWords';

 /**
 * Validation failure message template definitions
 *
 * @var array
 */
 protected $_messageTemplates = array(
   self::BAD_WORDS =&gt; "The text uses foul language"
 );

 /**
 * Badword array - change as required by your application
 */
 private $badwords = array('games', 'college', 'prewrcar', 'parrot', 'xx');

 /**
 * Defined by Zend_Validate_Interface
 *
 * Returns true if and only if $value does not contain bad words as defined by array
 *
 * @param  string $value
 * @return boolean
 */
 public function isValid($value)
 {
   $valueString = (string) $value;
   $this-&gt;_setValue($valueString);
   for($i=0; $i&lt;count($this-&gt;badwords); $i++) {
     if(strstr(strtoupper($valueString), strtoupper($this-&gt;badwords[$i]))) {
       $this-&gt;_error();
       return false;
     }
   }
  return true;
 }
}</pre>
<p>Whatever you personally consider &#8222;bad words&#8220;, add to the array, and rest assured that nobody can post those on your website. I omitted my selection out intentionally, but left some spam words in to show how it works. Make sure to add the f-word, and you can even add something like &#8222;<em>&lt;a href=</em>&#8220; to the array to avoid having links posted, but that subject will be in the &#8222;filter&#8220; article up next.</p>
<p>The post <a href="https://drzycimski.com/programmierung/no-mvc-zend-framework-zend_decorator-and-zend_validator/">No-MVC Zend Framework: Zend_Decorator and Zend_Validator</a> appeared first on <a href="https://drzycimski.com">Jörg Drzycimski</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://drzycimski.com/programmierung/no-mvc-zend-framework-zend_decorator-and-zend_validator/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
