This line may be confusing you:
if(!SmartyValidate::is_registered_form('uRegistro' ))
The form name you register has *nothing* do to with the form name in the HTML:
<form name="foo" ...> <-- no bearing on SmartyValidate form name!
The form name is only an internal form name you use when you register validators and call {validate} in the template.
Example:
PHP
---
if(empty($_POST)) {
SmartyValidate::connect($smarty); // connect to SmartyValidate
SmartyValidate::register_form('uRegistro',true); // register the "uRegistro" form, wipe out any previous settings
SmartyValidate::register_criteria('isAddr','isVali dAddress','uRegistro'); // register criteria to "uRegistro" form
} else {
SmartyValidate::is_valid($_POST,'uRegistro') { // apply validation criteria for "uRegistro" form to the $_POST vars
// show success page
} else {
// redraw form
}
}
TEMPLATE
--------
{validate form="uRegistro" id="isAddr" field="address" message="address info incorrect"} {* show message if there was an error *}
Now, the only time you *need* to register a custom form name is if you have more than one form to register at a time. Typically you only have one,so you can just use the "default" form, which doesn't need any explicit registering.
Example:
PHP
---
if(empty($_POST)) {
SmartyValidate::connect($smarty,true); // this implicitly registers the"default" form, wipes out any previous settings
SmartyValidate::register_criteria('isAddr','isVali dAddress'); // criteria gets applied to the "default" form
} else {
SmartyValidate::is_valid($_POST); // validate "default" form with the $_POST vars
// show success page
} else {
// redraw form
}
}
TEMPLATE:
{validate id="isAddr" field="address" message="address info incorrect"} {* assumes "default" form *}
Hope that s.
Monte
Reynier Perez Mira wrote:
>Hi to every body again. I still with problems. I don't know why this happened. If any can me?
>
>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: Reynier Perez Mira
>Enviado el: Friday, January 27, 2006 9:40 PM
>Para: Monte Ohrt
>CC: smarty-general@lists.php.net
>Asunto: RE: [SMARTY] SmartyValidate 2.6 and Smarty 2.6.12 doesn't work ...
>
>Hi:
>I still with SmartyValidate problems. After a rechecking for entire documentation in "Incutio", I found some elements to test if I do the right or not. The first is test is form are registered or not. So I rewrite again my old code and this is the way:
>
>************************************************* *****************
>if(empty($_POST)){
> SmartyValidate::connect($tpl, true);
> /* If I understand doc the form have not name is call 'default' but my form
> has a name and a id in this way: <form name="uRegister" id=" uRegister */
> ">. So I need to register my form in the way under */ SmartyValidate::register_form('uRegistro');
>/* Then I test if form was register or not */
> if(!SmartyValidate::is_registered_form('uRegistro' )){
> echo "Don't registered yet";
> }else{
> echo "Registered form";
> }
>/* This print "Registered form" */
>
>/* Then I register some validators needed */ SmartyValidate::register_validator('fnombre','uNom bre','notEmpty');
> SmartyValidate::register_validator('fapellidos','u Apellidos','notEmpty');
> SmartyValidate::register_validator('fdireccion','u Direccion','notEmpty');
> SmartyValidate::register_validator('fcorreo','uCor reo','isEmail');
> SmartyValidate::register_validator('fusuario','uUs uario','notEmpty');
> SmartyValidate::register_validator('fpassword','uP sw1:uPsw2', 'isEqual');
>
>/* I assign a template var because in a template according to the value taken for this var (display) I include some files */ $tpl->assign('display','register');
>}else{
>/*Here I don't change nothing because is the standard procedure for follow*/ SmartyValidate::connect($tpl);
> if(SmartyValidate::is_valid($_POST)) {
> SmartyValidate::disconnect();
> $tpl->display('success.tpl');
> } else {
> $tpl->assign($_POST);
> $tpl->display('form.tpl');
> }
>}
>************************************************* *****************
>So I rechecking again documentation and find another sutff but now abouttemplates. So I reprogramming again my old code and now this is:
>************************************************* *****************
><!-- User register form -->
><fieldset><legend>{#REGISTER_TITLE#|escape:"htmla ll"}</legend>
><form name="uRegistro" id="uRegistro" method="post" action="inser_user.php"> <table align="center" cellpadding="1" cellspacing="1"><tr> <td width="89" class="derecha">Nombre:</td> <td width="144"><input type="text" name="uNombre" id="uNombre" size="35" maxlength="35" value="{$uNombre}">
>
>/* In doc I found that {validate} tags require a parameter call criteria, this is optional or not? I'm lost here at this point. So I add this parameter to all my {validate} tags */ {validate id="fnombre" criteria="notEmpty" message="El campo Nombre no puede estar vacio"} </td></tr> <tr><td class="derecha">Apellidos:</td> <td><input type="text" name="uApellidos" id="uApellidos" size="35" maxlength="45" value="{$uApellidos}"> {validate id="fapellidos" criteria="notEmpty" message="El campo Apellidos no puede estar vacio"} </td></tr> <tr><td class="derecha">Dirección:</td>
><td><textarea name="uDireccion" id="uDireccion" cols="35" rows="5">{$uDireccion}</textarea> {validate id="fdireccion" criteria="notEmpty" message="El campo Direccion no puede estar vacio"} </td></tr> <tr><td class="derecha">eCorreo:</td> <td><input type="text" name="uCorreo" id="uCorreo" size="45" maxlength="150" value="{$uCorreo}"> {validate id="fcorreo" criteria="isEmail" message="El campo Correo Electrónico no puede estar vacio"} </td></tr> <tr><td class="derecha">Usuario:</td> <td><input type="text" name="uUsuario" id="uUsuario" size="35" maxlength="45" value="{$uUsuario}"> {validate id="fusuario" criteria="uUsuario" message="El campo Usuario no puede estar vacio"} </td></tr> <tr><td class="derecha">Contraseña:</td> <td><input type="password" name="uPsw1" id="uPsw1" size="35" maxlength="150" value="{$uPsw1}"> {validate id="fpassword" criteria="notEmpty" message="Los siguientes errores han ocurrido: El campo contraseña esta vacio o las contraseñas no coinciden"} </td></tr>
> <tr><td class="derecha">Confirmar contraseña:</td> <td><input type="password" name="uPsw2" id="uPsw2" size="35" maxlength="150" value="{$uPsw2}"> </td></tr> <tr><td colspan="2" class="center"><input type="submit" name="btn_Send" value="Enviar"></td></tr> </table></form></fieldset>
>************************************************* *****************
>
>So as you can see apparently nothing is wrong here, but when I send the form is sending without any validation. It means that if I leave all fields empty nothing happen and the form go where they was send, to inser_user.php script. So if any body can , I really miss some part of the documentation file or simply I have mistakes in my code?
>
>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...
>
>--
>Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
>
>
>
>
>
>!DSPAM:43de28a0299772383964272!
>
>
>
>