<?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>Blog d&#039;un développeur multi-support &#187; formulaire</title>
	<atom:link href="http://www.oni-ecchi.info/blog/tag/formulaire/feed" rel="self" type="application/rss+xml" />
	<link>http://www.oni-ecchi.info/blog</link>
	<description>[DIM] pour les intimes :)</description>
	<lastBuildDate>Mon, 06 Feb 2012 18:51:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Validé un formulaire en Ajax avec Symfony 1.1</title>
		<link>http://www.oni-ecchi.info/blog/decouverte-php/valide-un-formulaire-en-ajax-avec-symfony-11.html</link>
		<comments>http://www.oni-ecchi.info/blog/decouverte-php/valide-un-formulaire-en-ajax-avec-symfony-11.html#comments</comments>
		<pubDate>Sat, 06 Sep 2008 16:59:29 +0000</pubDate>
		<dc:creator>Guillaume chave</dc:creator>
				<category><![CDATA[Découverte PHP]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[formulaire]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.oni-ecchi.info/blog/?p=35</guid>
		<description><![CDATA[Dans ce billet nous allons voir comment utiliser Ajax pour valider champ par champ un formulaire constuit avec sfForm de Symfony 1.1. Je prend pour acquis que vous ayez lu / que vous connaissez la validatation de formulaire &#171;&#160;classique&#160;&#187; offert par sfForm. Tout est expliqué là et surtout là. En fait le souci avec les [...]]]></description>
			<content:encoded><![CDATA[<p>Dans ce billet nous allons voir comment utiliser Ajax pour valider champ par champ un formulaire constuit avec sfForm de <a href="http://www.oni-ecchi.info/blog/tag/symfony" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec Symfony">Symfony</a> 1.1.</p>
<p>Je prend pour acquis que vous ayez lu / que vous connaissez la validatation de formulaire &laquo;&nbsp;classique&nbsp;&raquo; offert par sfForm. Tout est expliqué <a href="http://www.symfony-project.org/book/forms/1_1/fr/" target="_blank">là </a>et surtout <a href="http://www.symfony-project.org/book/forms/1_1/fr/02-Form-Validation" target="_blank">là</a>.</p>
<p>En fait le souci avec les validateurs symfony 1.1 est qu&#8217;ils ne possèdent pas la méthode isValid() contraitement aux validateurs symfony 1.0. Du coup, quand on fait de l&#8217;ajax, nous sommes obligés de passer d&#8217;un type de validateur à un autre.</p>
<p>Cette exemple illuste le fait avec le validateur sfValidatorEmail (sf 1.1) et sfEmailValidator (sf 1.0). L&#8217;idée est de définir les paramêtres du validateur (les messages d&#8217;erreurs dans notre cas) qu&#8217;à un seul endroid afin de respecter le concept Dry (Don&#8217;t Repeat Yourself).</p>
<p>Voilà les étapes nécessaires pour mettre en place une validation de formulaire classique et &laquo;&nbsp;Ajaxé&nbsp;&raquo; :</p>
<ol>
<li>Vous créez vos widgets dans lib/form/MaClasseForm.class.<a href="http://www.oni-ecchi.info/blog/tag/php" class="st_tag internal_tag" rel="tag" title="Voir les articles classés avec php">php</a>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code9'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p359"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p35code9"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> MaClasseForm <span style="color: #000000; font-weight: bold;">extends</span> BaseMaClassForm
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> configure<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setWidgets</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'id'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInputHidden<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'FirstName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'LastName'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'Email'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'password_repeat'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'password'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfWidgetFormInput<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// On peut modifier les labels si besoin est ...</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLabels</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'FirstName'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Prenom'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'Email'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'addresse Email '</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'LastName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Nom'</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Vous définissez vos validateurs dans lib/form/MaClasseForm.class.php à la suite de la méthode configure()

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code10'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3510"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p35code10"><pre class="php" style="font-family:monospace;">&nbsp;
 <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValidators</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'id'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorPropelChoice<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'model'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Utilisateurs'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'column'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'FirstName'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'LastName'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'password'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'password_repeat'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorString<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'max_length'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Email'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorEmail<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'Birthday'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">new</span> sfValidatorDate<span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// J'en profite pour definir un nom formater des champs pour avoir $_POST['utilisateurs['email']] etc</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgetSchema</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setNameFormat</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utilisateurs[%s]'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</li>
<li> Normallement à ce stade vous pouvez utiliser la classe de formulaire dans votre fichier apps/MonApp/MonModule/actions/actions.class.php

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code11'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3511"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p35code11"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeMonAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formInscription</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MaClasseForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">request</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isMethod</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// récupère les champs du formulaire sous forme de tableau.</span>
     <span style="color: #000088;">$array_champ</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;utilisateurs&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formInscription</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array_champ</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">formInscription</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isValid</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
       <span style="color: #666666; font-style: italic;">// Formulaire valide.</span>
       <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Voilà la validation &laquo;&nbsp;classique&nbsp;&raquo; et faite. Et l&#8217;ajax dans tout ça ? On y vient ^^ Alors au lieu d&#8217;afficher le formulaire de manière classique (via le template adéquate apps/MonApp/MonModule/templates/MonActionSuccess.php)

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code12'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3512"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p35code12"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Au lieu de</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// On va rendre le template comme on le souhaite</span>
<span style="color: #666666; font-style: italic;">// Par souci de flemme je ne fait que le champ Email</span>
<span style="color: #339933;">&lt;</span>table<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Email '</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">:&lt;/</span>td<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Email '</span><span style="color: #009900;">&#93;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
   <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>span id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;error_for_email &quot;</span><span style="color: #339933;">&gt;</span>
                <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Email '</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasError</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;</span>ul <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;error_list&quot;</span><span style="color: #339933;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Email '</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&lt;</span>getError<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #339933;">&lt;</span>li <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;error_for&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$error</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span>
  <span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</li>
<li> Et maintenant on va jouer avec l&#8217;ajax pour vérifier ce champ email lors de la saisie.

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code13'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3513"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code" id="p35code13"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/************** Ajax Time :) *****************/</span>
<span style="color: #666666; font-style: italic;">// Dans le template on met :</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Crée l'observateur pour le champ utilisateurs_email du formulaire.</span>
<span style="color: #b1b100;">echo</span> observe_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;utilisateurs_email&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'update'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;error_for_email&quot;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;MonModule/VerifierEmail&quot;</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'with'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;'email='+ value&quot;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

</li>
<li>On rajoute l&#8217;action VerifierEmail() dans le fichier d&#8217;actions.

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code14'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3514"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code" id="p35code14"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeVerifierEmail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	 <span style="color: #666666; font-style: italic;">// Initialisation des variables internes</span>
	 <span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000088;">$array_erreur</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	 <span style="color: #666666; font-style: italic;">// Récupère le validateur d'email définit dans lib/form/MaClasseForm.class.php</span>
	 <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MaClasseForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000088;">$validateur_form</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidatorSchema</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000088;">$all_validateurs_field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$validateur_form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFields</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$all_validateurs_field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;email&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
	 <span style="color: #666666; font-style: italic;">// Récupere le bon code d'erreur</span>
	 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
	 <span style="color: #009900;">&#123;</span>
	 	<span style="color: #000088;">$array_erreur</span> <span style="color: #339933;">=</span>	<a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email_error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
	 <span style="color: #b1b100;">else</span>
	 <span style="color: #009900;">&#123;</span>
	 	<span style="color: #000088;">$array_erreur</span> <span style="color: #339933;">=</span>	<a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email_error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;invalid&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
&nbsp;
	 <span style="color: #666666; font-style: italic;">// Crée un validateur d'email hérité de Symfony 1.0</span>
	 <span style="color: #000088;">$validateur_email</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfEmailValidator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #666666; font-style: italic;">// Un peu de Dry (Don't Repeat Yourself) afin d'éviter d'avoir des messages d'erreurs définit à deux endroits différents.</span>
	 <span style="color: #000088;">$validateur_email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$array_erreur</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #666666; font-style: italic;">// Dispatcheur vers le bon templates</span>
	 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$validateur_email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chaine_a_verifier</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	 <span style="color: #009900;">&#123;</span>
	 	<span style="color: #000088;">$message_a_afficher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajax_error&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message_retour</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;reussi&quot;</span><span style="color: #339933;">=&gt;</span>true<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
	 <span style="color: #b1b100;">else</span>
	 <span style="color: #009900;">&#123;</span>
	 	<span style="color: #000088;">$message_a_afficher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajax_error&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message_retour</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;reussi&quot;</span><span style="color: #339933;">=&gt;</span>false<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	 <span style="color: #009900;">&#125;</span>
&nbsp;
	 <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderText</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message_a_afficher</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

</li>
<li>Donc en fait on met à jour le &laquo;&nbsp;span&nbsp;&raquo; error_for_email avec le résultat de l&#8217;appel de la méthode VerifierEmail(). J&#8217;ai utilisé un template partial car le but est de le réutiliser pour tous les appels en Ajax. Celui ci n&#8217;est pas bien compliqué

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code15'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3515"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p35code15"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>li <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&lt;?php if(<span style="color: #006699; font-weight: bold;">$reussi</span>) echo &quot;</span>accept_for<span style="color: #0000ff;">&quot;; else echo &quot;</span>error_for<span style="color: #0000ff;">&quot;; ?&gt;&quot;</span><span style="color: #339933;">&gt;&amp;</span>amp<span style="color: #339933;">;</span>nbsp<span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</li>
<li>Et voilà, le formulaire fonctionne classiquement et dispose de vérifications en Ajax aussi.</li>
</ol>
<p>Nous venons de voir le validateur d&#8217;Email, mais tous fonctionnent sur le même principe. Voici la méthode pour utiliser le validateur de Sting qui diffère un peu.</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p35code16'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3516"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
</pre></td><td class="code" id="p35code16"><pre class="php" style="font-family:monospace;">   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> executeVerifierPseudo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">// Initialisation des variables internes</span>
    <span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequestParameter</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pseudo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Récupère le validateur de pseudo</span>
    <span style="color: #000088;">$form</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MaClasseForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$validateur_form</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidatorSchema</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$all_validateurs_field</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$validateur_form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFields</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$validateurs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$all_validateurs_field</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;FirstName&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$pseudo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$validateurs</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValidators</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$pseudo</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pseudo</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// Crée un validateur de String sf1.0</span>
    <span style="color: #000088;">$validateur_pseudo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> sfStringValidator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$validateur_pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">initialize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'min'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;min_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'min_error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;min_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'max'</span> <span style="color: #339933;">=&gt;</span><span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;max_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'max_error'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;max_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'required'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Dispatcheur vers le bon templates</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$validateur_pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">execute</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chaine_a_verifier</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$message_a_afficher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajax_error&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message_retour</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;reussi&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$bool</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chaine_a_verifier</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$test</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;required&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #666666; font-style: italic;">// Remplace les jokers des messages d'erreurs.</span>
     <span style="color: #000088;">$min</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;min_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$max</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pseudo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;max_length&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$message_retour</span><span style="color: #339933;">=</span>    <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#%value%#&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$chaine_a_verifier</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$message_retour</span><span style="color: #339933;">=</span>    <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#%min_length%#&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$min</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$message_retour</span><span style="color: #339933;">=</span>    <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#%max_length%#&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$max</span><span style="color: #339933;">,</span><span style="color: #000088;">$message_retour</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$message_a_afficher</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPartial</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajax_error&quot;</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;message&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$message_retour</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;reussi&quot;</span><span style="color: #339933;">=&gt;</span>false<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderText</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message_a_afficher</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p> Et voilà c&#8217;est fini :) </p>
]]></content:encoded>
			<wfw:commentRss>http://www.oni-ecchi.info/blog/decouverte-php/valide-un-formulaire-en-ajax-avec-symfony-11.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

