View previous topic :: View next topic |
Author |
Message |
___seb Smarty Rookie
Joined: 04 Oct 2007 Posts: 7 Location: fortress europe
|
Posted: Fri Feb 08, 2008 3:23 pm Post subject: Smarty validate : never valid [Resolved] |
|
|
Hi,
I can't have a positive response, SmartyValidates always says that the input value is not valid .
php :
Code: |
session_start();
require_once('common.php');
error_reporting(E_ALL);
require_once(SMARTY_DIR.'SmartyValidate.class.php');
$smarty = new Page();
SmartyValidate::connect($smarty, true);
if(!isset($_POST['envoi_mail']))
{
SmartyValidate::register_validator('id', 'nom', 'notEmpty');
}
if(isset($_POST['envoi_mail']))
{
if(SmartyValidate::is_valid($_POST))
{
die('valid :)');
SmartyValidate::disconnect();
}
else
{
print_r($_POST);
die('invalid :(');
}
} |
tpl :
Code: |
<form action="{$code_langue}/contact.html" method="post">
<fieldset>
<input type="hidden" name="envoi_mail" />
{if $nom_dest}
<input type="hidden" name="destinataire" value="{$id_dest}" />
{/if}
<dl>
<dt>{#titre_section#}</dt>
<dd>
{validate id="id" message="message d'erreur" }
<label for="nom_expediteur">{#nom#} </label>
<input type="text" name="nom" />
</dd>
</dl>
<input type="image" src="./img/bouton_suivant_or.png" class="submit"/>
</fieldset>
</form>
|
what's wrong ?
I always have invalid on screen. And caching is disabled.
Last edited by ___seb on Mon Feb 11, 2008 3:59 pm; edited 1 time in total |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Feb 08, 2008 3:27 pm Post subject: |
|
|
does $_POST['nom'] have a value when it fails? Is PHP error display on, and are you checking those? |
|
Back to top |
|
___seb Smarty Rookie
Joined: 04 Oct 2007 Posts: 7 Location: fortress europe
|
Posted: Fri Feb 08, 2008 3:33 pm Post subject: |
|
|
Quote: | Array ( [envoi_mail] => [nom] => sdfdfg [x] => 15 [y] => 5 ) invalid
|
$_POST['nom'] has a value
error display is on : error_reporting(E_ALL); |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Feb 08, 2008 4:02 pm Post subject: |
|
|
And the validator information is in the $_SESSION ? |
|
Back to top |
|
___seb Smarty Rookie
Joined: 04 Oct 2007 Posts: 7 Location: fortress europe
|
Posted: Fri Feb 08, 2008 4:10 pm Post subject: |
|
|
var_dump($_SESSION);
Quote: |
array(1) {
["SmartyValidate"]=>
array(1) {
["default"]=>
array(4) {
["registered_funcs"]=>
array(2) {
["criteria"]=>
array(0) {
}
["transform"]=>
array(0) {
}
}
["validators"]=>
array(0) {
}
["is_error"]=>
bool(false)
["is_init"]=>
bool(true)
}
}
} |
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Feb 08, 2008 4:31 pm Post subject: |
|
|
I don't see your validator in the session, make sure that register_validator() happens when the form is first drawn. |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Feb 08, 2008 4:34 pm Post subject: |
|
|
Ah, I see the problem.
Do this:
Code: | SmartyValidate::connect($smarty, true); |
Only on the first draw of the page when you run register_validator(). After that, just do:
Code: | SmartyValidate::connect($smarty); |
The second param of "true" resets the validation session.
So to fix your code:
Code: |
session_start();
require_once('common.php');
error_reporting(E_ALL);
require_once(SMARTY_DIR.'SmartyValidate.class.php');
$smarty = new Page();
if(!isset($_POST['envoi_mail']))
{
SmartyValidate::connect($smarty, true);
SmartyValidate::register_validator('id', 'nom', 'notEmpty');
}
if(isset($_POST['envoi_mail']))
{
SmartyValidate::connect($smarty);
if(SmartyValidate::is_valid($_POST))
{
die('valid :)');
SmartyValidate::disconnect();
}
else
{
print_r($_POST);
die('invalid :(');
}
} |
|
|
Back to top |
|
___seb Smarty Rookie
Joined: 04 Oct 2007 Posts: 7 Location: fortress europe
|
Posted: Sat Feb 09, 2008 1:52 pm Post subject: |
|
|
ok, thanks for the help.
I'll try on monday... |
|
Back to top |
|
___seb Smarty Rookie
Joined: 04 Oct 2007 Posts: 7 Location: fortress europe
|
Posted: Mon Feb 11, 2008 3:58 pm Post subject: ok |
|
|
that's ok
thank you very much _________________ my little outdated blog |
|
Back to top |
|
|