Afficher un message
Vieux 23/01/2006, 16h50   #4
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
 
Page generated in 0,07124 seconds with 9 queries