<?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>Agence de Développement Informatique du Nord &#187; validator</title>
	<atom:link href="http://blog.adin.pro/tag/validator/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.adin.pro</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 26 Dec 2019 08:54:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.1.1</generator>
	<item>
		<title>Magento multi fields validator for RIB</title>
		<link>http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/</link>
		<comments>http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/#comments</comments>
		<pubDate>Fri, 28 Feb 2014 08:56:34 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[magento]]></category>
		<category><![CDATA[RIB]]></category>
		<category><![CDATA[validator]]></category>
		<category><![CDATA[VarienForm]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=360</guid>
		<description><![CDATA[<p>Magento come with a great form validator : VarienForm. These is a lot of existing validator, for every usage and you can easyly add some. This is how you can do it with a commun example, how to check RIB &#8230; <a href="http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/">Magento multi fields validator for RIB</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>Magento come with a great form validator : VarienForm. These is a lot of existing validator, for every usage and you can easyly add some. This is how you can do it with a commun example, how to check RIB bank account.</p>
<p>First, our html code</p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul class=&quot;inlineblockli&quot;&gt;
	&lt;li&gt;
		&lt;label for=&quot;code_bank_pb&quot;&gt;&lt;?php echo $this-&gt;__('bank code') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextB validate-digits required-entry validate-length minimum-length-5 maximum-length-5&quot; id=&quot;code_bank_pb&quot; maxlength=&quot;5&quot; name=&quot;prelevement[code_bank_pb]&quot;&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;label for=&quot;code_guichet_pb&quot;&gt;&lt;?php echo $this-&gt;__('branch code') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextB validate-digits required-entry validate-length minimum-length-5 maximum-length-5&quot; id=&quot;code_guichet_pb&quot; maxlength=&quot;5&quot; name=&quot;prelevement[code_guichet_pb]&quot;&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;label for=&quot;num_compte&quot;&gt;&lt;?php echo $this-&gt;__('Account number to be debited') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextBig3 validate-digits required-entry validate-length minimum-length-11 maximum-length-11&quot; id=&quot;num_compte&quot; maxlength=&quot;11&quot; name=&quot;prelevement[num_compte]&quot;&gt;
	&lt;/li&gt;
	&lt;li&gt;
		&lt;label for=&quot;key_rib&quot;&gt;&lt;?php echo $this-&gt;__('RIB key') ?&gt;&lt;/label&gt;
                &lt;input type=&quot;text&quot; class=&quot;inputText inputTextSm3 validate-digits required-entry validate-compte validate-length minimum-length-2 maximum-length-2&quot; id=&quot;key_rib&quot; maxlength=&quot;2&quot; name=&quot;prelevement[key_rib]&quot;&gt;
	&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>We first do a lenght validation with these 3 class : validate-length minimum-length-11 maximum-length-11</p>
<p>Then we validate the rib with this class : validate-compte<br />
You will tell me this validator doesn&#8217;t exeist. That&#8217;s right, let&#8217;s create it.</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
    //&lt;![CDATA[
    Validation.addAllThese(
        [
            ['validate-compte', '&lt;?php echo Mage::helper('rating')-&gt;__('Please check your RIB account') ?&gt;', function(v) {
                var code_banque = jQuery('#code_bank_pb').val();
                var code_guichet = jQuery('#code_guichet_pb').val();
                var numero_compte = jQuery('#num_compte').val();
                var cle           = jQuery('#key_rib').val();

                var CompteTmp = code_banque + code_guichet + numero_compte + cle;

                while(CompteTmp.length &gt; 9)
                {
                    var CompteTmp2 = CompteTmp.substr(0,9) % 97;
                    CompteTmp = CompteTmp2 + CompteTmp.substr(9,CompteTmp.length);
                }
                var CompteTmp2 = CompteTmp.substr(0,9) % 97;

                if(CompteTmp2 % 97 == 0)
                {
                    return true;
                }
                return false;
            }]
        ]
    );
    //]]&gt;
&lt;/script&gt;
</pre>
<p>Some explainations :</p>
<pre class="brush: jscript; title: ; notranslate">
jQuery('#code_bank_pb').val();
</pre>
<p>Magento use prototype, tu use jQuery, use jQuery instead of $</p>
<p>For the multi field validation, I grab the different fields from this</p>
<pre class="brush: jscript; title: ; notranslate">
var code_banque   = jQuery('#code_bank_pb').val();
var code_guichet  = jQuery('#code_guichet_pb').val();
var numero_compte = jQuery('#num_compte').val();
var cle           = jQuery('#key_rib').val();
</pre>
<p>I don&#8217;t know if this is the cleaner way to do (not really usable for another code) but it works.<br />
If you always use the same input id, you can reuse this code on another site.</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/">Magento multi fields validator for RIB</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2014-02-28/magento-multi-fields-validator-for-rib/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fatal error : Declaration of {{path}}::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate()</title>
		<link>http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/</link>
		<comments>http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/#comments</comments>
		<pubDate>Tue, 08 Oct 2013 20:01:30 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Sonata]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=311</guid>
		<description><![CDATA[<p>You are trying to setup a custom validator on Sonata and you get this error : Fatal error: Declaration of Adin\AdminBundle\Admin\AnnonceAdmin::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() in /home/www/arlogis/src/Adin/AdminBundle/Admin/AnnonceAdmin.php on line 250 Don&#8217;t panic, just add this at the &#8230; <a href="http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/">Fatal error : Declaration of {{path}}::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate()</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You are trying to setup a custom validator on Sonata and you get this error :</p>
<p>Fatal error: Declaration of Adin\AdminBundle\Admin\AnnonceAdmin::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() in /home/www/arlogis/src/Adin/AdminBundle/Admin/AnnonceAdmin.php on line 250 </p>
<p>Don&#8217;t panic, just add this at the begining of your class</p>
<pre class="brush: php; title: ; notranslate">
use Sonata\AdminBundle\Validator\ErrorElement;
</pre>
<p>in our example it&#8217;s in this file  : /AdminBundle/Admin/AnnonceAdmin.php</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/">Fatal error : Declaration of {{path}}::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate()</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-10-08/fatal-error-declaration-of-pathvalidate-must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() error message</title>
		<link>http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/</link>
		<comments>http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/#comments</comments>
		<pubDate>Sun, 06 Oct 2013 14:53:03 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Sonata]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[Symfony2]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=299</guid>
		<description><![CDATA[<p>You are using sonata and want to validate some fields. You innocently add the validate function to your Admin file Then, you get this error : You checked to AdminInterface file the declaration is the same. To fix it, you &#8230; <a href="http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/">Continue reading <span class="meta-nav">&#8594;</span></a></p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/">must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() error message</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You are using sonata and want to validate some fields.<br />
You innocently add the validate function to your Admin file</p>
<pre class="brush: php; title: ; notranslate">
function validate(ErrorElement $errorElement, $object)
{
}
</pre>
<p>Then, you get this error :</p>
<pre class="brush: bash; title: ; notranslate">
Fatal error: Declaration of Adin\AdminBundle\Admin\AnnonceAdmin::validate() must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() in /home/www/arlogis/src/Adin/AdminBundle/Admin/AnnonceAdmin.php on line 251 
</pre>
<p>You checked to AdminInterface file the declaration is the same.</p>
<p>To fix it, you need to use additionnal namespace :</p>
<pre class="brush: php; title: ; notranslate">
use Sonata\AdminBundle\Validator\ErrorElement;
use Symfony\Component\Validator\ValidatorInterface;
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/">must be compatible with that of Sonata\AdminBundle\Admin\AdminInterface::validate() error message</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-10-06/must-be-compatible-with-that-of-sonataadminbundleadminadmininterfacevalidate-error-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony validator custom error message</title>
		<link>http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/</link>
		<comments>http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/#comments</comments>
		<pubDate>Mon, 13 May 2013 07:55:21 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=195</guid>
		<description><![CDATA[<p>If you need to customize your validator error messages, you can use the setMessage() function. On your Form class (ex: /lib/form/doctrine/DemandeForm.class.php)</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/">Symfony validator custom error message</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>If you need to customize your validator error messages, you can use the setMessage() function.<br />
On your Form class (ex: /lib/form/doctrine/DemandeForm.class.php)</p>
<pre class="brush: php; title: ; notranslate">
//sfValidatorInteger
$this-&gt;validatorSchema['produit_ean']-&gt;setMessage('invalid', 'ean should be integer');
$this-&gt;validatorSchema['produit_ean']-&gt;setMessage('min', 'ean must be at least %min%');
$this-&gt;validatorSchema['produit_ean']-&gt;setMessage('max', 'ean must be at least %max%');

//sfValidatorDate
$this-&gt;validatorSchema['date']-&gt;setMessage('bad_format', 'Format must be dd/mm/YYYY');
$this-&gt;validatorSchema['date']-&gt;setMessage('max', 'Date should be after than 01/01/2013');
$this-&gt;validatorSchema['date']-&gt;setMessage('min', 'Date should be before than 01/02/2013');

//required
$this-&gt;validatorSchema['date']-&gt;setMessage('required', 'Date is mandatory');

</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/">Symfony validator custom error message</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-05-13/symfony-validator-custom-error-message/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>unexpected extra form field named</title>
		<link>http://blog.adin.pro/2013-01-25/unexpected-extra-form-field-named/</link>
		<comments>http://blog.adin.pro/2013-01-25/unexpected-extra-form-field-named/#comments</comments>
		<pubDate>Fri, 25 Jan 2013 19:48:28 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=89</guid>
		<description><![CDATA[<p>You had an unbound input in your form and Symfony throw you an &#8220;unexpected extra form field named &#8216;yourfield'&#8221; error ? Don&#8217;t worry, add a sfValitorPass() in your form description :</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-01-25/unexpected-extra-form-field-named/">unexpected extra form field named</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>You had an unbound input in your form and Symfony throw you an &#8220;unexpected extra form field named &#8216;yourfield'&#8221; error ?</p>
<p>Don&#8217;t worry, add a sfValitorPass() in your form description :</p>
<pre class="brush: php; title: ; notranslate">
class DemandeForm extends BaseDemandeForm
{
   public function configure()
   {
        $this-&gt;validatorSchema['yourfield'] = new sfValidatorPass();
   }
</pre>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2013-01-25/unexpected-extra-form-field-named/">unexpected extra form field named</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2013-01-25/unexpected-extra-form-field-named/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Symfony 1.4 multi fields validator</title>
		<link>http://blog.adin.pro/2012-11-28/symfony-1-4-multi-fields-validator/</link>
		<comments>http://blog.adin.pro/2012-11-28/symfony-1-4-multi-fields-validator/#comments</comments>
		<pubDate>Wed, 28 Nov 2012 14:29:33 +0000</pubDate>
		<dc:creator><![CDATA[blogadmin]]></dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[validator]]></category>

		<guid isPermaLink="false">http://blog.adin.pro/?p=34</guid>
		<description><![CDATA[<p>In your form class (lib/form/doctrine/classForm.class.php) save this class in a lib folder, for exemple apps/frontend/lib/sfValidatorMultiFields.class.php The keys points are : &#8211; use $this->validatorSchema->setPostValidator() in your form class &#8211; all fields are now available from the $values array ($values[&#8216;field1&#8242;], $values[&#8216;field2&#8242;] &#8230;)</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2012-11-28/symfony-1-4-multi-fields-validator/">Symfony 1.4 multi fields validator</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></description>
				<content:encoded><![CDATA[<p>In your form class (lib/form/doctrine/classForm.class.php)</p>
<pre class="brush: php; title: ; notranslate">
  $this-&gt;validatorSchema-&gt;setPostValidator(
      new sfValidatorMultiFields(
        array('field1', 'field2', 'field3'),
        array('labels' =&gt; array('name1', 'name2', 'name3')),
        array('global_invalid' =&gt; 'Multi fields error')));
</pre>
<p>save this class in a lib folder, for exemple apps/frontend/lib/sfValidatorMultiFields.class.php</p>
<pre class="brush: php; title: ; notranslate">
&lt;?
class sfValidatorMultiFields extends sfValidatorSchema
{
 
  public function __construct(array $fields, $options = array(), $messages = array())
  {
    $this-&gt;addOption('fields', $fields);

    $this-&gt;addMessage('invalid', 'Error with this field');
    $this-&gt;addMessage('global_invalid', 'Multi fields error');

    parent::__construct(null, $options, $messages);
  }

  protected function doClean($values)
  {
    $valid = false;
    foreach ($this-&gt;getOption('fields') as $field) {
	//put here your validation code
        // ex: $values[$field] ....
    }
    //another example, at least one field in not empty
    if($values['field1'] != '' || $values['field2'] != '' || $values['field3'] != '')
    {
        $valid = true;
    }

    if ($valid)
    {
      $errorSchema = new sfValidatorErrorSchema($this);

        // The global error
        $errorSchema-&gt;addError(new sfValidatorError($this, 'global_invalid', array()));
      }

      // Fields error
      $error = new sfValidatorError($this, 'invalid', array()));

      // Add the error for each defined fields
      foreach ($this-&gt;getOption('fields') as $field)
      {
        $errorSchema-&gt;addError($error, $field);
      }

      throw $errorSchema;
    }

    return $values;
  }
}
?&gt;
</pre>
<p>The keys points are :<br />
 &#8211; use $this->validatorSchema->setPostValidator() in your form class<br />
 &#8211; all fields are now available from the $values array ($values[&#8216;field1&#8242;], $values[&#8216;field2&#8242;] &#8230;)</p>
<p>The post <a rel="nofollow" href="http://blog.adin.pro/2012-11-28/symfony-1-4-multi-fields-validator/">Symfony 1.4 multi fields validator</a> appeared first on <a rel="nofollow" href="http://blog.adin.pro">Agence de Développement Informatique du Nord</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.adin.pro/2012-11-28/symfony-1-4-multi-fields-validator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
