Hello Anso,
Thank you for your help ! Ok for custom validator
I've created the snippet :
<?php
$pattern = '`^[[:digit:]]{14}$`'; // accepts only 14 numbers (no letters, no space etc...)
if(!preg_match($pattern, $value)){
$validator->addError('N° SIRET','Le n° SIRET doit contenir 14 chiffres'); // error message if the value does not matche the pattern
return false;
}
but it doesn't work. FormIt validates even if there is one letter.
If I refer to
http://rtfm.modx.com/display/ADDON/FormIt.Validators#FormIt.Validators-CustomValidators, there is a return $success; at the end of the snippet... So I tried to make :
<?php
$value = (float)$value;
$pattern = '`^[[:digit:]]{14}$`';
$success = preg_match($pattern, $value);
if (!$success) {
// Note how we can add an error to the field here.
$validator->addError('N° SIRET','Le n° SIRET doit contenir 14 chiffres');
}
return $success;
No chance...
I've tested the isBigEnough snippet and it works.
Here is a part of my call :
[[!FormIt?
&hooks=`spam,email,redirect`
&emailSubject=`Nouvelle inscription`
&emailTpl=`formItInscriptionAnnonceur`
&emailTo=`[email protected]`
&redirectTo=`17`
&customValidators=`isBigEnough`
&validate=`pagetitle:required,
societe_siret:isBigEnough`
]]
<p>[[+fi.error.error_message]]</p>
<form class="form" action="[[~[[*id]]]]" method="post">
<input name="nospam:blank" type="hidden" />
<input name="resource_id" type="hidden" value="[[+fi.id]]" />
<div class="champ">
<label for="form_pagetitle"><span class="req">*</span>Nom de votre enseigne :
<span class="error">[[!+fi.error.pagetitle]]</span>
</label>
<input type="text" name="pagetitle" id="form_pagetitle" value="[[!+fi.pagetitle]]" />
</div>
<div class="champ">
<label for="form_siret"><span class="req">*</span>N° SIRET :
<span class="error">[[!+fi.error.societe_siret]]</span>
</label>
<input type="text" name="societe_siret" id="form_siret" value="[[!+fi.societe_siret]]" />
</div>
Thank you