PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.smarty.general > SmartyValidate 2.6 and Smarty 2.6.12 doesn't work ...
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
SmartyValidate 2.6 and Smarty 2.6.12 doesn't work ...

Réponse
 
LinkBack Outils de la discussion
Vieux 23/01/2006, 14h57   #1 (permalink)
Reynier Perez Mira
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut SmartyValidate 2.6 and Smarty 2.6.12 doesn't work ...

Hi:
Well, after all and a little latest (¿Jan 23?) "Happy New Year".

I try to construct a web application in these days. I decide use Smarty as my template engine because it's perfectly and powerful. I have some form in which user can add news, sign guestbook and some other stuff. These form need to be validate after send it to database. So ... searching in Smarty forum I found SmartyValidate class.

I read the doc form website and setup this in my application:

index.php
------------------------------------------------------------------
/* Start new session each time */
session_start();

setlocale(LC_ALL, 'esp_ESP');

include_once('../config.inc.php');
require_once('../api/smarty/Smarty.class.php');
require_once('../api/smarty/SmartyValidate.class.php');
include_once('../api/dbase/adodb-exceptions.inc.php');
include_once('../api/dbase/adodb.inc.php');

/* Setup Smarty Class */
$tpl = new Smarty();
$tpl->template_dir = '../' . cnf_TemplateDir;
$tpl->compile_dir = '../' . cnf_TemplateDir . cnf_CompileDir;
$tpl->config_dir = '../' . cnf_TemplateDir . cnf_ConfigDir;
$tpl->cache_dir = '../' . cnf_TemplateDir . cnf_CacheDir;
$tpl->compile_check = cnf_CompileCheck;
$tpl->debugging = false;

if(SmartyValidate::is_valid($_POST)) {
SmartyValidate::connect($tpl, true);
SmartyValidate::register_validator('uLog','uLogin' ,'notEmpty');
SmartyValidate::register_validator('uPas','uPasswd ','notEmpty');
$tpl->display('a_home.tpl');
} else {
SmartyValidate::connect($tpl);
if(SmartyValidate::is_valid($_POST)) {
SmartyValidate::disconnect();
$tpl->display('success.tpl');
} else {
$tpl->assign($_POST);
$tpl->display('a_home.tpl');
}
}
------------------------------------------------------------------

a_home.tpl
------------------------------------------------------------------
<form name="frm_aLogin" id="frm_aLogin" method="post" action="index.php?opt=chkuLogin" enctype="multipart/form-data">
<fieldset>
<legend>Login de Administrador</legend>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td width="25%" class="derecha">Usuario:</td>
<td width="75%">
<input type="text" name="uLogin" id="uLogin" size="35" maxlength="35" />{validate id="uLog" message="El campo usuario no puede estar vacío"}
</td>
</tr>
<tr>
<td class="derecha">Contraseña:</td>
<td><input type="password" name="uPasswd" id="uPasswd" size="35" maxlength="250" />{validate id="uPas" message="El campo contraseña no puede estar vacío"}
</td>
</tr>
<tr>
<td class="centro" colspan="2"><input type="submit" name="btn_Login" id="btn_Login" value="Entrar ..." /></td>
</tr>
</table>
</fieldset>
</form>
------------------------------------------------------------------

As you can see, nothing is strange here in this code. Well when I call the file from my FF browser, ex: http://localhost/admincp/index.php
This warnings appear:

------------------------------------------------------------------
Warning: Smarty error: validate: validator id 'uLog' is not registered. in D:\WebServer\WWW\simpro\api\smarty\Smarty.class.ph p on line 1095

Warning: Smarty error: validate: validator id 'uPas' is not registered. in D:\WebServer\WWW\simpro\api\smarty\Smarty.class.ph p on line 1095
------------------------------------------------------------------

What's wrong in my code?
I work with PHP 5.1.2, have this something to see?

Best,
ReynierPM
4to. año Ing. Informática
Usuario registrado de Linux: #310201
************************************************** ***********************
El programador superhéroe aprende de compartir sus conocimientos.
Es el referente de sus compañeros. Todo el mundo va a preguntarle
y él, secretamente, lo fomenta porque es así como adquiere su legendaria
sabiduría: escuchando ayudando a los demás...
  Réponse avec citation
Vieux 23/01/2006, 16h25   #2 (permalink)
Monte Ohrt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] SmartyValidate 2.6 and Smarty 2.6.12 doesn't work ...

Do not call SmartyValidat::is_valid($_POST) when the form has not been
initialized.

A possible approach to this (as per the examples):

if(!empty($_POST)) {
// test is_valid()
} else {
// initialize form
}



Reynier Perez Mira wrote:

>Hi:
>Well, after all and a little latest (¿Jan 23?) "Happy New Year".
>
>I try to construct a web application in these days. I decide use Smarty as my template engine because it's perfectly and powerful. I have some form in which user can add news, sign guestbook and some other stuff. These form need to be validate after send it to database. So ... searching in Smarty forum I found SmartyValidate class.
>
>I read the doc form website and setup this in my application:
>
>index.php
>------------------------------------------------------------------
>/* Start new session each time */
>session_start();
>
>setlocale(LC_ALL, 'esp_ESP');
>
>include_once('../config.inc.php');
>require_once('../api/smarty/Smarty.class.php');
>require_once('../api/smarty/SmartyValidate.class.php');
>include_once('../api/dbase/adodb-exceptions.inc.php');
>include_once('../api/dbase/adodb.inc.php');
>
>/* Setup Smarty Class */
>$tpl = new Smarty();
>$tpl->template_dir = '../' . cnf_TemplateDir;
>$tpl->compile_dir = '../' . cnf_TemplateDir . cnf_CompileDir;
>$tpl->config_dir = '../' . cnf_TemplateDir . cnf_ConfigDir;
>$tpl->cache_dir = '../' . cnf_TemplateDir . cnf_CacheDir;
>$tpl->compile_check = cnf_CompileCheck;
>$tpl->debugging = false;
>
>if(SmartyValidate::is_valid($_POST)) {
> SmartyValidate::connect($tpl, true);
> SmartyValidate::register_validator('uLog','uLogin' ,'notEmpty');
> SmartyValidate::register_validator('uPas','uPasswd ','notEmpty');
> $tpl->display('a_home.tpl');
>} else {
> SmartyValidate::connect($tpl);
> if(SmartyValidate::is_valid($_POST)) {
> SmartyValidate::disconnect();
> $tpl->display('success.tpl');
> } else {
> $tpl->assign($_POST);
> $tpl->display('a_home.tpl');
> }
>}
>------------------------------------------------------------------
>
>a_home.tpl
>------------------------------------------------------------------
><form name="frm_aLogin" id="frm_aLogin" method="post" action="index.php?opt=chkuLogin" enctype="multipart/form-data">
> <fieldset>
> <legend>Login de Administrador</legend>
> <table width="100%" cellpadding="0" cellspacing="0" border="0">
> <tr>
> <td width="25%" class="derecha">Usuario:</td>
> <td width="75%">
> <input type="text" name="uLogin" id="uLogin" size="35" maxlength="35" />{validate id="uLog" message="El campo usuario no puede estar vacío"}
> </td>
> </tr>
> <tr>
> <td class="derecha">Contraseña:</td>
> <td><input type="password" name="uPasswd" id="uPasswd" size="35" maxlength="250" />{validate id="uPas" message="El campo contraseña no puede estar vacío"}
> </td>
> </tr>
> <tr>
> <td class="centro" colspan="2"><input type="submit" name="btn_Login" id="btn_Login" value="Entrar ..." /></td>
> </tr>
> </table>
> </fieldset>
> </form>
>------------------------------------------------------------------
>
>As you can see, nothing is strange here in this code. Well when I call the file from my FF browser, ex: http://localhost/admincp/index.php
>This warnings appear:
>
>------------------------------------------------------------------
>Warning: Smarty error: validate: validator id 'uLog' is not registered. in D:\WebServer\WWW\simpro\api\smarty\Smarty.class.ph p on line 1095
>
>Warning: Smarty error: validate: validator id 'uPas' is not registered. in D:\WebServer\WWW\simpro\api\smarty\Smarty.class.ph p on line 1095
>------------------------------------------------------------------
>
>What's wrong in my code?
>I work with PHP 5.1.2, have this something to see?
>
>Best,
>ReynierPM
>4to. año Ing. Informática
>Usuario registrado de Linux: #310201
>************************************************* ************************
>El programador superhéroe aprende de compartir sus conocimientos.
>Es el referente de sus compañeros. Todo el mundo va a preguntarle
>y él, secretamente, lo fomenta porque es así como adquiere su legendaria
>sabiduría: escuchando ayudando a los demás...
>
>
>

  Réponse avec citation
Vieux 23/01/2006, 16h28   #3 (permalink)
Monte Ohrt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] SmartyValidate 2.6 and Smarty 2.6.12 doesn't work ...

Your code is almost right, just change:

if(SmartyValidate::is_valid($_POST)) {

to:

if(!empty($_POST)) {






Reynier Perez Mira wrote:

>Hi:
>Well, after all and a little latest (¿Jan 23?) "Happy New Year".
>
>I try to construct a web application in these days. I decide use Smarty as my template engine because it's perfectly and powerful. I have some form in which user can add news, sign guestbook and some other stuff. These form need to be validate after send it to database. So ... searching in Smarty forum I found SmartyValidate class.
>
>I read the doc form website and setup this in my application:
>
>index.php
>------------------------------------------------------------------
>/* Start new session each time */
>session_start();
>
>setlocale(LC_ALL, 'esp_ESP');
>
>include_once('../config.inc.php');
>require_once('../api/smarty/Smarty.class.php');
>require_once('../api/smarty/SmartyValidate.class.php');
>include_once('../api/dbase/adodb-exceptions.inc.php');
>include_once('../api/dbase/adodb.inc.php');
>
>/* Setup Smarty Class */
>$tpl = new Smarty();
>$tpl->template_dir = '../' . cnf_TemplateDir;
>$tpl->compile_dir = '../' . cnf_TemplateDir . cnf_CompileDir;
>$tpl->config_dir = '../' . cnf_TemplateDir . cnf_ConfigDir;
>$tpl->cache_dir = '../' . cnf_TemplateDir . cnf_CacheDir;
>$tpl->compile_check = cnf_CompileCheck;
>$tpl->debugging = false;
>
>if(SmartyValidate::is_valid($_POST)) {
> SmartyValidate::connect($tpl, true);
> SmartyValidate::register_validator('uLog','uLogin' ,'notEmpty');
> SmartyValidate::register_validator('uPas','uPasswd ','notEmpty');
> $tpl->display('a_home.tpl');
>} else {
> SmartyValidate::connect($tpl);
> if(SmartyValidate::is_valid($_POST)) {
> SmartyValidate::disconnect();
> $tpl->display('success.tpl');
> } else {
> $tpl->assign($_POST);
> $tpl->display('a_home.tpl');
> }
>}
>------------------------------------------------------------------
>
>a_home.tpl
>------------------------------------------------------------------
><form name="frm_aLogin" id="frm_aLogin" method="post" action="index.php?opt=chkuLogin" enctype="multipart/form-data">
> <fieldset>
> <legend>Login de Administrador</legend>
> <table width="100%" cellpadding="0" cellspacing="0" border="0">
> <tr>
> <td width="25%" class="derecha">Usuario:</td>
> <td width="75%">
> <input type="text" name="uLogin" id="uLogin" size="35" maxlength="35" />{validate id="uLog" message="El campo usuario no puede estar vacío"}
> </td>
> </tr>
> <tr>
> <td class="derecha">Contraseña:</td>
> <td><input type="password" name="uPasswd" id="uPasswd" size="35" maxlength="250" />{validate id="uPas" message="El campo contraseña no puede estar vacío"}
> </td>
> </tr>
> <tr>
> <td class="centro" colspan="2"><input type="submit" name="btn_Login" id="btn_Login" value="Entrar ..." /></td>
> </tr>
> </table>
> </fieldset>
> </form>
>------------------------------------------------------------------
>
>As you can see, nothing is strange here in this code. Well when I call the file from my FF browser, ex: http://localhost/admincp/index.php
>This warnings appear:
>
>------------------------------------------------------------------
>Warning: Smarty error: validate: validator id 'uLog' is not registered. in D:\WebServer\WWW\simpro\api\smarty\Smarty.class.ph p on line 1095
>
>Warning: Smarty error: validate: validator id 'uPas' is not registered. in D:\WebServer\WWW\simpro\api\smarty\Smarty.class.ph p on line 1095
>------------------------------------------------------------------
>
>What's wrong in my code?
>I work with PHP 5.1.2, have this something to see?
>
>Best,
>ReynierPM
>4to. año Ing. Informática
>Usuario registrado de Linux: #310201
>************************************************* ************************
>El programador superhéroe aprende de compartir sus conocimientos.
>Es el referente de sus compañeros. Todo el mundo va a preguntarle
>y él, secretamente, lo fomenta porque es así como adquiere su legendaria
>sabiduría: escuchando ayudando a los demás...
>
>
>

  Réponse avec citation
Vieux 23/01/2006, 16h50   #4 (permalink)
Monte Ohrt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [SMARTY] SmartyValidate 2.6 and Smarty 2.6.12 doesn't work ...

Monte Ohrt wrote:

> Your code is almost right, just change:
>
> if(SmartyValidate::is_valid($_POST)) {
>
> to:
>
> if(!empty($_POST)) {
>
>


oops, make that:

if(empty($_POST)) {

I'll note that testing if $_POST is empty isn't always an accurate
approach in every situation, another approach is to test if the form is
registered:

if (!SmartyValidate::is_registered_form('default')) {

>
>
>
>
> Reynier Perez Mira wrote:
>
>> Hi:
>> Well, after all and a little latest (¿Jan 23?) "Happy New Year".
>> I try to construct a web application in these days. I decide use
>> Smarty as my template engine because it's perfectly and powerful. I
>> have some form in which user can add news, sign guestbook and some
>> other stuff. These form need to be validate after send it to
>> database. So ... searching in Smarty forum I found SmartyValidate class.
>> I read the doc form website and setup this in my application:
>>
>> index.php
>> ------------------------------------------------------------------
>> /* Start new session each time */
>> session_start();
>>
>> setlocale(LC_ALL, 'esp_ESP');
>>
>> include_once('../config.inc.php');
>> require_once('../api/smarty/Smarty.class.php');
>> require_once('../api/smarty/SmartyValidate.class.php');
>> include_once('../api/dbase/adodb-exceptions.inc.php');
>> include_once('../api/dbase/adodb.inc.php');
>>
>> /* Setup Smarty Class */
>> $tpl = new Smarty();
>> $tpl->template_dir = '../' . cnf_TemplateDir;
>> $tpl->compile_dir = '../' . cnf_TemplateDir . cnf_CompileDir;
>> $tpl->config_dir = '../' . cnf_TemplateDir . cnf_ConfigDir;
>> $tpl->cache_dir = '../' . cnf_TemplateDir . cnf_CacheDir;
>> $tpl->compile_check = cnf_CompileCheck;
>> $tpl->debugging = false;
>>
>> if(SmartyValidate::is_valid($_POST)) {
>> SmartyValidate::connect($tpl, true);
>> SmartyValidate::register_validator('uLog','uLogin' ,'notEmpty');
>> SmartyValidate::register_validator('uPas','uPasswd ','notEmpty');
>> $tpl->display('a_home.tpl');
>> } else {
>> SmartyValidate::connect($tpl);
>> if(SmartyValidate::is_valid($_POST)) {
>> SmartyValidate::disconnect();
>> $tpl->display('success.tpl');
>> } else {
>> $tpl->assign($_POST);
>> $tpl->display('a_home.tpl');
>> }
>> }
>> ------------------------------------------------------------------
>>
>> a_home.tpl
>> ------------------------------------------------------------------
>> <form name="frm_aLogin" id="frm_aLogin" method="post"
>> action="index.php?opt=chkuLogin" enctype="multipart/form-data">
>> <fieldset>
>> <legend>Login de Administrador</legend> <table width="100%"
>> cellpadding="0" cellspacing="0" border="0">
>> <tr>
>> <td width="25%" class="derecha">Usuario:</td>
>> <td width="75%">
>> <input type="text" name="uLogin" id="uLogin" size="35"
>> maxlength="35" />{validate id="uLog" message="El campo usuario no
>> puede estar vacío"}
>> </td>
>> </tr>
>> <tr>
>> <td class="derecha">Contraseña:</td>
>> <td><input type="password" name="uPasswd" id="uPasswd" size="35"
>> maxlength="250" />{validate id="uPas" message="El campo contraseña no
>> puede estar vacío"}
>> </td>
>> </tr>
>> <tr>
>> <td class="centro" colspan="2"><input type="submit"
>> name="btn_Login" id="btn_Login" value="Entrar ..." /></td>
>> </tr>
>> </table>
>> </fieldset>
>> </form>
>> ------------------------------------------------------------------
>>
>> As you can see, nothing is strange here in this code. Well when I
>> call the file from my FF browser, ex: http://localhost/admincp/index.php
>> This warnings appear:
>> ------------------------------------------------------------------
>> Warning: Smarty error: validate: validator id 'uLog' is not
>> registered. in D:\WebServer\WWW\simpro\api\smarty\Smarty.class.ph p on
>> line 1095
>>
>> Warning: Smarty error: validate: validator id 'uPas' is not
>> registered. in D:\WebServer\WWW\simpro\api\smarty\Smarty.class.ph p on
>> line 1095
>> ------------------------------------------------------------------
>>
>> What's wrong in my code?
>> I work with PHP 5.1.2, have this something to see?
>>
>> Best, ReynierPM
>> 4to. año Ing. Informática
>> Usuario registrado de Linux: #310201
>> ************************************************** ***********************
>>
>> El programador superhéroe aprende de compartir sus conocimientos. Es
>> el referente de sus compañeros. Todo el mundo va a preguntarle y él,
>> secretamente, lo fomenta porque es así como adquiere su legendaria
>> sabiduría: escuchando ayudando a los demás...
>>
>>
>>

>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 10h51.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18986 seconds with 12 queries