Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Smarty validate : never valid [Resolved]

 
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
___seb
Smarty Rookie


Joined: 04 Oct 2007
Posts: 7
Location: fortress europe

PostPosted: Fri Feb 08, 2008 3:23 pm    Post subject: Smarty validate : never valid [Resolved] Reply with quote

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 Sad 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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Feb 08, 2008 3:27 pm    Post subject: Reply with quote

does $_POST['nom'] have a value when it fails? Is PHP error display on, and are you checking those?
Back to top
View user's profile Send private message Visit poster's website
___seb
Smarty Rookie


Joined: 04 Oct 2007
Posts: 7
Location: fortress europe

PostPosted: Fri Feb 08, 2008 3:33 pm    Post subject: Reply with quote

Quote:
Array ( [envoi_mail] => [nom] => sdfdfg [x] => 15 [y] => 5 ) invalid Sad


$_POST['nom'] has a value
error display is on : error_reporting(E_ALL);
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Feb 08, 2008 4:02 pm    Post subject: Reply with quote

And the validator information is in the $_SESSION ?
Back to top
View user's profile Send private message Visit poster's website
___seb
Smarty Rookie


Joined: 04 Oct 2007
Posts: 7
Location: fortress europe

PostPosted: Fri Feb 08, 2008 4:10 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Feb 08, 2008 4:31 pm    Post subject: Reply with quote

I don't see your validator in the session, make sure that register_validator() happens when the form is first drawn.
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Feb 08, 2008 4:34 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
___seb
Smarty Rookie


Joined: 04 Oct 2007
Posts: 7
Location: fortress europe

PostPosted: Sat Feb 09, 2008 1:52 pm    Post subject: Reply with quote

ok, thanks for the help.

I'll try on monday...
Back to top
View user's profile Send private message Visit poster's website
___seb
Smarty Rookie


Joined: 04 Oct 2007
Posts: 7
Location: fortress europe

PostPosted: Mon Feb 11, 2008 3:58 pm    Post subject: ok Reply with quote

that's ok
thank you very much Smile
_________________
my little outdated blog
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP