RE: [SMARTY] SmartyValidate 2.6 and Smarty 2.6.12 doesn't work ...

From: Date: Mon, 23 Jan 2006 18:59:24 +0000
Subject: RE: [SMARTY] SmartyValidate 2.6 and Smarty 2.6.12 doesn't work ...
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13259@lists.php.net to get a copy of this message
I not understand what do you need I'm do? Is this: ----------------------------------- if(empty($_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'); } } ----------------------------------- Or ... 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... -----Mensaje original----- De: Monte Ohrt [mailto:monte@ohrt.com] Enviado el: Monday, January 23, 2006 11:58 am Para: Reynier Perez Mira CC: smarty-general@lists.php.net Asunto: Re: [SMARTY] SmartyValidate 2.6 and Smarty 2.6.12 doesn't work .... The form is not validating at all? Try this: if (empty($_POST)) remove the registration check. When you first come to the form, it should register it. When you submit the form, it should validate it. Reynier Perez Mira wrote: >Nothing ... Monte excuse me if I a little stupid. I change the code again but the form still >send without any validate. I check the session file and this is the content: >----------------------------------------------- >SmartyValidate|a:1:{s:7:"default";a:4:{s:16:"registered_funcs";a:2:{s:8:"criteria";a:0:{}s:9:"transform";a:0:{}}s:10:"validators";a:2:{i:0;a:8:{s:5:"field";s:6:"uLogin";s:2:"id";s:4:"uLog";s:8:"criteria";s:8:"notEmpty";s:7:"message";s:37:"El >campo usuario no puede estar >vacío";s:4:"trim";b:0;s:5:"empty";b:0;s:4:"halt";b:0;s:9:"transform";N;}i:1;a:8:{s:5:"field";s:7:"uPasswd";s:2:"id";s:4:"uPas";s:8:"criteria";s:8:"notEmpty";s:7:"message";s:40:"El >campo contraseña no puede estar >vacío";s:4:"trim";b:0;s:5:"empty";b:0;s:4:"halt";b:0;s:9:"transform";N;}}s:8:"is_error";b:0;s:7:"is_init";b:0;}} >----------------------------------------------- >So if Smarty working fine I believe, what's really wrong here? I can find it. > >Regards >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... > >-----Mensaje original----- >De: Monte Ohrt [mailto:monte@ohrt.com] >Enviado el: Monday, January 23, 2006 11:45 am >Para: Reynier Perez Mira >CC: smarty-general@lists.php.net >Asunto: Re: [SMARTY] SmartyValidate 2.6 and Smarty 2.6.12 doesn't work .... > >The form needs reset each time it is "new", so maybe use empty($_POST) >along with the register test: > >if(!SmartyValidate::is_registered_form() || empty($_POST)) { > > > >Reynier Perez Mira wrote: > > > >>Well, I follow your instructions and change the bad code. The code now is this: >>-------------------------------- >>if(!SmartyValidate::is_registered_form('default')) { >> 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'); >> } >> } >>-------------------------------- >>But when I submit the form and leave fields empty, nothing is validate!!! So ... when I >>click the back button in my FF browser then the messages: " El campo usuario no puede estar >>vacío" and " El campo contraseña no puede estar vacío" appears. Why this? >> >> >>Regards >>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... >> >>-----Mensaje original----- >>De: Monte Ohrt [mailto:monte@ohrt.com] >>Enviado el: Monday, January 23, 2006 11:34 am >>Para: Reynier Perez Mira >>CC: smarty-general@lists.php.net >>Asunto: Re: [SMARTY] SmartyValidate 2.6 and Smarty 2.6.12 doesn't work .... >> >>that is the name of the form. if you didn't name it when you registered, >>then 'default' is correct. You can also leave it empty: >> >>is_registered_form() >> >>Reynier Perez Mira wrote: >> >> >> >> >> >>>Hi Monte: >>>Understand every, but I have one doubt: what's 'default'? a name for a >>>form or a id or something ... >>> >>>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... >>> >>>-----Mensaje original----- >>>De: Monte Ohrt [mailto:monte@ohrt.com] >>>Enviado el: Monday, January 23, 2006 10:51 am >>>Para: Reynier Perez Mira >>>CC: smarty-general@lists.php.net >>>Asunto: 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.php on >>>>>line 1095 >>>>> >>>>>Warning: Smarty error: validate: validator id 'uPas' is not >>>>>registered. in D:\WebServer\WWW\simpro\api\smarty\Smarty.class.php 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... >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>>>> >>> >>> >>> >>> >> >> >> >> >> >> >> >> >> >> >> >> >> > > > > > > > > >!DSPAM:43d51809286061294912330! > > > >

« previous php.smarty.general (#13259) next »