Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

How I do this?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
reynier
Smarty Pro


Joined: 12 Apr 2005
Posts: 104
Location: Cuba

PostPosted: Wed Apr 13, 2005 4:16 pm    Post subject: How I do this? Reply with quote

I make a register system using Smarty and SmartyValidate. I have to pages one call register.tpl in wich the user can introduce his data and other call tworegister.tpl in wich allow users to check if data are or not correct. Well, when I go forwards all it's fine. The validation works fine and all the vars are store in session vars temporaly, but when I click in button that call: javascript:history.go(-1) some errors appear. Below has a entire
register.php
[php:1:5b5e0141d3]<?php
session_start();
require("class/smarty/Smarty.class.php");
require("class/smarty/SmartyValidate.class.php");
include_once("language/lang-spanish.php");
include_once('class/DB.php');

$template = new Smarty();

/* Class smarty config */
$template->template_dir = "themes/";
$template->compile_dir = "themes/themes_c/";
$template->config_dir = "themes/config/";
$template->compile_check = true;

$dsn = "mysql://jcce:jccegrm03@localhost/jovenclub";

$database = DB::connect($dsn);
if (DB::isError($database)) {
die($database->getMessage());
}

/* Assign values to constants or dinamic vars */
$template->assign("COPYRIGHT",COPYRIGHT);
$template->assign('yesterday', strtotime('-1 day'));

$modulo = isset($_GET['mod'])?$_GET['mod']:die("Error");
$template->display("header.tpl");
switch($modulo){
case "register":
$template->assign("U_NEW_REGISTER",_U_NEW_REGISTER);
$template->assign("UNAME",_UNAME);
$template->assign("UCORREO",_UCORREO);
$template->assign("UNICK",_UNICK);
$template->assign("UPASS1",_UPASS1);
$template->assign("UPASS2",_UPASS2);
$template->assign("UPASSB",_UPASSB);
$template->assign("SECURITYCODE","<img src=\"securitycode.php\">");
$template->assign("OTROSDATOS",_OTROSDATOS);
$template->assign("UICQ",_UICQ);
$template->assign("UYIM",_UYIM);
$template->assign("UMSN",_UMSN);
$template->assign("UAOL",_UAOL);
$template->assign("UWWW",_USWWW);
$template->assign("UINTERESES",_UINTERESES);
$template->assign("UOCUPACION",_UOCUPACION);
$template->assign("UFIRMA",_UFIRMA);
$template->assign("UPCORREO",_UPCORREO);
$template->assign("UNCORREO",_UNCORREO);
$template->assign("UAVATAR",_UAVATAR);
$template->assign("UREGISTER",_UREGISTER);
$template->assign("UOBLIGATORIEDDATA",_OBLIGATORIEDDATA);

/* Init validate Forms */
if(empty($_POST)) {
SmartyValidate::connect($template,true);
SmartyValidate::register_validator('uname','uname','notEmpty',false,false,'trim');
SmartyValidate::register_validator('ucorreo','ucorreo','isEmail',false,false,'trim');
SmartyValidate::register_validator('unickname','unickname','notEmpty',true,false,'trim');
SmartyValidate::register_validator('upass1','upass1:upass2','isEqual');
SmartyValidate::register_validator('uicq','uicq','notEmpty',true);
SmartyValidate::register_validator('uyim','uyim','notEmpty',true);
SmartyValidate::register_validator('umsn','umsn','notEmpty',true);
SmartyValidate::register_validator('uaol','uaol','notEmpty',true);
SmartyValidate::register_validator('uweb','uweb','notEmpty',true);
SmartyValidate::register_validator('uintereses','uintereses','notEmpty',true);
SmartyValidate::register_validator('uocupacion','uocupacion','notEmpty',true);
SmartyValidate::register_validator('ufirma','ufirma','notEmpty',true);

$template->display("register.tpl");
}else{
SmartyValidate::connect($template);
if(SmartyValidate::is_valid($_POST)) {
SmartyValidate::disconnect();

/* Register variable session for previous use */
$_SESSION['urname'] = isset($_POST['uname'])?$_POST['uname']:"";
$_SESSION['ucorreo'] = isset($_POST['ucorreo'])?$_POST['ucorreo']:"";
$_SESSION['unickname'] = isset($_POST['unickname'])?$_POST['unickname']:"";
$_SESSION['uicq'] = isset($_POST['uicq'])?$_POST['uicq']:"";
$_SESSION['uyim'] = isset($_POST['uyim'])?$_POST['uyim']:"";
$_SESSION['umsn'] = isset($_POST['umsn'])?$_POST['umsn']:"";
$_SESSION['uaol'] = isset($_POST['uaol'])?$_POST['uaol']:"";
$_SESSION['uweb'] = isset($_POST['uweb'])?$_POST['uweb']:"";
$_SESSION['uintereses'] = isset($_POST['uintereses'])?$_POST['uintereses']:"";
$_SESSION['uocupacion'] = isset($_POST['uocupacion'])?$_POST['uocupacion']:"";
$_SESSION['ufirma'] = isset($_POST['ufirma'])?$_POST['ufirma']:"";
$_SESSION['umailpublic'] = isset($_POST['umailpublic'])?$_POST['umailpublic']:"";
$_SESSION['unotifiymail'] = isset($_POST['unotifiymail'])?$_POST['unotifiymail']:"";

$template->assign("ULASTSTEP", _ULASTSTEP);
$template->assign("UNAMESESSION", $_SESSION['urname']);
$template->assign("UCORREOSESSION", $_SESSION['ucorreo']);
$template->assign("UNICKSESSION", $_SESSION['unickname']);
$template->assign("UICQSESSION", $_SESSION['uicq']);
$template->assign("UYIMSESSION", $_SESSION['uyim']);
$template->assign("UMSNSESSION", $_SESSION['umsn']);
$template->assign("UAOLSESSION", $_SESSION['uaol']);
$template->assign("USWWWSESSION", $_SESSION['uweb']);
$template->assign("UINTERESESSESSION", $_SESSION['uintereses']);
$template->assign("UOCUPACIONSESSION", $_SESSION['uocupacion']);
$template->assign("UFIRMASESSION", $_SESSION['ufirma']);
$template->assign("UPCORREOSESSION", _UPCORREOSESSION);
$template->assign("UNCORREOSESSION", _UNCORREOSESSION);
$template->assign("UREGISTERSUCESFULLY", _UREGISTERSUCESFULLY);
$template->assign("UBACKREGISTER", _UBACKREGISTER);

$template->display('tworegister.tpl');
}else{
$template->assign($_POST);
$template->display('register.tpl');
}
}
break;
case "con":
$template->display("login.tpl");
break;
case "lost_password":
break;
case "user_cp":
break;
case "user_cp":
break;
case "new_user":
break;
}
$template->display("footer.tpl");
?>[/php:1:5b5e0141d3]
register.tpl
[php:1:5b5e0141d3]<?php
<tr><td class="padding-tb"><div align="center">
<form action="users.php?mod=register" method="post" enctype="multipart/form-data" name="register_form" id="register_form" a>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="table">
<tr>
<td colspan="2" align="center" class="th">{$U_NEW_REGISTER}</td>
</tr>
<tr>
<td colspan="2" align="center" class="topnav">{$UOBLIGATORIEDDATA}</span></td>
</tr>
<tr>
<td width="31%" align="right">{$UNAME}</td>
<td width="69%" align="left">
<input name="uname" type="text" id="uname" size="25" maxlength="25" value="{$uname|escape:"htmlall"}"><br>
{validate id="uname" message='<span class="errorline">Debe introducir su(s) nombre(s) y apellidos antes de continuar con el registro</span>'}
</td>
</tr>
<tr>
<td align="right">{$UCORREO}</td>
<td align="left">
<input name="ucorreo" type="text" id="ucorreo" size="50" maxlength="250" value="{$ucorreo|escape:"htmlall"}"><br>
{validate id="ucorreo" message='<span class="errorline">Debe introducir una dirección de correo electrónico válida antes de continuar con el registro</span>'}
</td>
</tr>
<tr>
<td align="right">{$UNICK}</td>
<td align="left">
<input name="unickname" type="text" id="unickname" size="35" maxlength="35" value="{$unickname|escape:"htmlall"}"><br>
{validate id="unickname" message='<span class="errorline">Debe introducir un nombre de usuario antes de continuar con el registro</span>'}
</td>
</tr>
<tr>
<td align="right">{$UPASS1}</td>
<td align="left">
<input name="upass1" type="password" id="upass1" size="35" maxlength="250"><br>
<input name="uencpass" type="hidden" id="uencpass">
</td>
</tr>
<tr>
<td align="right">{$UPASS2}</td>
<td align="left">
<input name="upass2" type="password" id="upass2" size="35" maxlength="250"><br>
{validate id="upass1" message='<span class="errorline">Las contraseñas introducidas no coinciden</span>'}
</td>
</tr>
<tr>
<td colspan="2" align="center">{$UPASSB}</td>
</tr>
<tr>
<td align="right">&</td>
<td>{$SECURITYCODE}</td>
</tr>
<tr>
<td colspan="2" align="center" class="topnav">{$OTROSDATOS}</td>
</tr>
<tr>
<td align="right">{$UICQ}</td>
<td align="left">
<input name="uicq" type="text" id="uicq" size="16" maxlength="16" value="{$uicq|escape:"htmlall"}">
{validate id="uicq" message=''}
</td>
</tr>
<tr>
<td align="right">{$UYIM}</td>
<td align="left">
<input name="uyim" type="text" id="uyim" size="25" maxlength="35" value="{$uyim|escape:"htmlall"}">
{validate id="uyim" message=''}
</td>
</tr>
<tr>
<td align="right">{$UMSN}</td>
<td align="left">
<input name="umsn" type="text" id="umsn" size="25" maxlength="35" value="{$umsn|escape:"htmlall"}">
{validate id="umsn" message=''}
</td>
</tr>
<tr>
<td align="right">{$UAOL}</td>
<td align="left">
<input name="uaol" type="text" id="uaol" size="25" maxlength="35" value="{$uaol|escape:"htmlall"}">
{validate id="uaol" message=''}
</td>
</tr>
<tr>
<td align="right">{$USWWW}</td>
<td align="left">
<input name="uweb" type="text" id="uweb" size="50" maxlength="500" value="{$uweb|escape:"htmlall"}">
{validate id="uweb" message=''}
</td>
</tr>
<tr>
<td valign="top" align="right">{$UINTERESES}</td>
<td align="left">
<textarea name="uintereses" cols="35" rows="5" wrap="VIRTUAL" id="uintereses">{$uintereses|escape:"htmlall"}</textarea>
{validate id="uintereses" message=''}
</td>
</tr>
<tr>
<td valign="top" align="right">{$UOCUPACION}</td>
<td align="left">
<textarea name="uocupacion" cols="35" rows="5" wrap="VIRTUAL" id="uocupacion">{$uocupacion|escape:"htmlall"}</textarea>
{validate id="uocupacion" message=''}
</td>
</tr>
<tr>
<td valign="top" align="right">{$UFIRMA}</td>
<td align="left">
<textarea name="ufirma" cols="35" rows="5" wrap="VIRTUAL" id="ufirma">{$ufirma|escape:"htmlall"}</textarea>
{validate id="ufirma" message=''}
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="umailpublic" type="checkbox" id="umailpublic" value="1" checked>{$UPCORREO}
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input name="unotifiymail" type="checkbox" id="unotifiymail" value="1">{$UNCORREO}
</td>
</tr>
<tr>
<td align="right">{$UAVATAR}</td>
<td align="left"><input name="uavataruploaded" type="file" id="uavataruploaded" size="35"></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="ubtn_send" type="submit" id="ubtn_send" value="{$UREGISTER}"></td>
</tr>
<tr>
<td colspan="2" align="center">&</td>
</tr>
</table>
</form></div>
</td>
</tr>?>[/php:1:5b5e0141d3]
tworegister.tpl
[php:1:5b5e0141d3]<?php
<tr><td class="padding-tb"><div align="center">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" class="table">
<tr>
<td colspan="2" align="center" class="topnav">{$ULASTSTEP}</td>
</tr>
<tr>
<td width="31%" align="right">{$UNAME}</td>
<td width="69%" align="left">{$UNAMESESSION}</td>
</tr>
<tr>
<td align="right">{$UCORREO}</td>
<td align="left">{$UCORREOSESSION}</td>
</tr>
<tr>
<td align="right">{$UNICK}</td>
<td align="left">{$UNICKSESSION}</td>
</tr>
{if $UICQSESSION neq ""}
<tr>
<td align="right">{$UICQ}</td>
<td align="left">{$UICQSESSION}</td>
</tr>
{/if}
{if $UYIMSESSION neq ""}
<tr>
<td align="right">{$UYIM}</td>
<td align="left">{$UYIMSESSION}</td>
</tr>
{/if}
{if $UMSNSESSION neq ""}
<tr>
<td align="right">{$UMSN}</td>
<td align="left">{$UMSNSESSION}</td>
</tr>
{/if}
{if $UAOLSESSION neq ""}
<tr>
<td align="right">{$UAOL}</td>
<td align="left">{$UAOLSESSION}</td>
</tr>
{/if}
{if $USWWWSESSION neq ""}
<tr>
<td align="right">{$USWWW}</td>
<td align="left">{$USWWWSESSION}</td>
</tr>
{/if}
{if $UINTERESESSESSION neq ""}
<tr>
<td valign="top" align="right">{$UINTERESES}</td>
<td align="left">{$UINTERESESSESSION|nl2br}</td>
</tr>
{/if}
{if $UOCUPACIONSESSION neq ""}
<tr>
<td valign="top" align="right">{$UOCUPACION}</td>
<td align="left">$UOCUPACIONSESSION|nl2br}</td>
</tr>
{/if}
{if $UFIRMASESSION neq ""}
<tr>
<td valign="top" align="right">{$UFIRMA}</td>
<td align="left">{$UFIRMASESSION|nl2br}</td>
</tr>
{/if}
{if $UPCORREOSESSION eq 1}
<tr>
<td valign="top" align="right">{$UPCORREO}</td>
<td align="left">{$UPCORREOSESSION}</td>
</tr>
{/if}
{if $UNCORREOSESSION eq 1}
<tr>
<td valign="top" align="right">{$UNCORREO}</td>
<td align="left">{$UNCORREOSESSION}</td>
</tr>
{/if}
<tr>
<td colspan="2" align="center"><input name="ubtn_back" type="button" id="ubtn_back" value="{$UBACKREGISTER}" onClick="javascript:history.go(-1)"><input name="ubtn_send" type="submit" id="ubtn_send" value="{$UREGISTERSUCESFULLY}"></td>
</tr>
<tr>
<td colspan="2" align="center">&</td>
</tr>
</table>
</div>
</td>
</tr>?>[/php:1:5b5e0141d3]
****************************************************************
The errors came from SmartyValidate. See some of them:
Quote:

Warning: Smarty error: validate: validator id 'uname' is not registered. in D:\WWW\jclub\class\smarty\Smarty.class.php on line 1088


Warning: Smarty error: validate: validator id 'ucorreo' is not registered. in D:\WWW\jclub\class\smarty\Smarty.class.php on line 1088

Warning: Smarty error: validate: validator id 'unickname' is not registered. in D:\WWW\jclub\class\smarty\Smarty.class.php on line 1088

and others. I try to put into input and textareas the content that user enter in previous step to facilitate the register and they can not enter again all data. How I do this ?

Regards Idea
_________________
ReynierPM
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Apr 13, 2005 5:24 pm    Post subject: Reply with quote

Hi reynier: can you please use the Addons forum for SmartyValidate questions?

Thanks.
Back to top
View user's profile Send private message
reynier
Smarty Pro


Joined: 12 Apr 2005
Posts: 104
Location: Cuba

PostPosted: Wed Apr 13, 2005 5:56 pm    Post subject: Upsss soury Reply with quote

My apology. Move the POST to a Foro dedicated to AddOn I know now where I publish

Regards Sad
_________________
ReynierPM
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
mohrt
Administrator


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

PostPosted: Wed Apr 13, 2005 7:14 pm    Post subject: Reply with quote

You have to register your validators before displaying the registration template (the one with {validate ...} tags)

So, BE SURE you have registered the validators with SmartyValidate::register_validator() BEFORE displaying the template the first time.
Back to top
View user's profile Send private message Visit poster's website
reynier
Smarty Pro


Joined: 12 Apr 2005
Posts: 104
Location: Cuba

PostPosted: Wed Apr 13, 2005 7:41 pm    Post subject: But ... Reply with quote

I not understand what you try to say me. If you see the code before your reply, all validators are register before show template file. See that:

[php:1:cebfa360e1]<?php
case "register":
$template->assign("U_NEW_REGISTER",_U_NEW_REGISTER);
$template->assign("UNAME",_UNAME);
$template->assign("UCORREO",_UCORREO);
$template->assign("UNICK",_UNICK);
$template->assign("UPASS1",_UPASS1);
$template->assign("UPASS2",_UPASS2);
$template->assign("UPASSB",_UPASSB);
$template->assign("SECURITYCODE","<img src=\"securitycode.php\">");
$template->assign("OTROSDATOS",_OTROSDATOS);
$template->assign("UICQ",_UICQ);
$template->assign("UYIM",_UYIM);
$template->assign("UMSN",_UMSN);
$template->assign("UAOL",_UAOL);
$template->assign("UWWW",_USWWW);
$template->assign("UINTERESES",_UINTERESES);
$template->assign("UOCUPACION",_UOCUPACION);
$template->assign("UFIRMA",_UFIRMA);
$template->assign("UPCORREO",_UPCORREO);
$template->assign("UNCORREO",_UNCORREO);
$template->assign("UAVATAR",_UAVATAR);
$template->assign("UREGISTER",_UREGISTER);
$template->assign("UOBLIGATORIEDDATA",_OBLIGATORIEDDATA);

/* Init validate Forms */
if(empty($_POST)) {
SmartyValidate::connect($template,true);
SmartyValidate::register_validator('uname','uname','notEmpty',false,false,'trim');
SmartyValidate::register_validator('ucorreo','ucorreo','isEmail',false,false,'trim');
SmartyValidate::register_validator('unickname','unickname','notEmpty',true,false,'trim');
SmartyValidate::register_validator('upass1','upass1:upass2','isEqual');
SmartyValidate::register_validator('uicq','uicq','notEmpty',true);
SmartyValidate::register_validator('uyim','uyim','notEmpty',true);
SmartyValidate::register_validator('umsn','umsn','notEmpty',true);
SmartyValidate::register_validator('uaol','uaol','notEmpty',true);
SmartyValidate::register_validator('uweb','uweb','notEmpty',true);
SmartyValidate::register_validator('uintereses','uintereses','notEmpty',true);
SmartyValidate::register_validator('uocupacion','uocupacion','notEmpty',true);
SmartyValidate::register_validator('ufirma','ufirma','notEmpty',true);

$template->display("register.tpl");
}else{
SmartyValidate::connect($template);
if(SmartyValidate::is_valid($_POST)) {
SmartyValidate::disconnect();

/* Register variable session for previous use */
$_SESSION['urname'] = isset($_POST['uname'])?$_POST['uname']:"";
$_SESSION['ucorreo'] = isset($_POST['ucorreo'])?$_POST['ucorreo']:"";
$_SESSION['unickname'] = isset($_POST['unickname'])?$_POST['unickname']:"";
$_SESSION['uicq'] = isset($_POST['uicq'])?$_POST['uicq']:"";
$_SESSION['uyim'] = isset($_POST['uyim'])?$_POST['uyim']:"";
$_SESSION['umsn'] = isset($_POST['umsn'])?$_POST['umsn']:"";
$_SESSION['uaol'] = isset($_POST['uaol'])?$_POST['uaol']:"";
$_SESSION['uweb'] = isset($_POST['uweb'])?$_POST['uweb']:"";
$_SESSION['uintereses'] = isset($_POST['uintereses'])?$_POST['uintereses']:"";
$_SESSION['uocupacion'] = isset($_POST['uocupacion'])?$_POST['uocupacion']:"";
$_SESSION['ufirma'] = isset($_POST['ufirma'])?$_POST['ufirma']:"";
$_SESSION['umailpublic'] = isset($_POST['umailpublic'])?$_POST['umailpublic']:"";
$_SESSION['unotifiymail'] = isset($_POST['unotifiymail'])?$_POST['unotifiymail']:"";

$template->assign("ULASTSTEP", _ULASTSTEP);
$template->assign("UNAMESESSION", $_SESSION['urname']);
$template->assign("UCORREOSESSION", $_SESSION['ucorreo']);
$template->assign("UNICKSESSION", $_SESSION['unickname']);
$template->assign("UICQSESSION", $_SESSION['uicq']);
$template->assign("UYIMSESSION", $_SESSION['uyim']);
$template->assign("UMSNSESSION", $_SESSION['umsn']);
$template->assign("UAOLSESSION", $_SESSION['uaol']);
$template->assign("USWWWSESSION", $_SESSION['uweb']);
$template->assign("UINTERESESSESSION", $_SESSION['uintereses']);
$template->assign("UOCUPACIONSESSION", $_SESSION['uocupacion']);
$template->assign("UFIRMASESSION", $_SESSION['ufirma']);
$template->assign("UPCORREOSESSION", _UPCORREOSESSION);
$template->assign("UNCORREOSESSION", _UNCORREOSESSION);
$template->assign("UREGISTERSUCESFULLY", _UREGISTERSUCESFULLY);
$template->assign("UBACKREGISTER", _UBACKREGISTER);

$template->display('tworegister.tpl');
}else{
$template->assign($_POST);
$template->display('register.tpl');
}
}
break;
?>[/php:1:cebfa360e1]
So what's wrong?
Regards
_________________
ReynierPM
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
mohrt
Administrator


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

PostPosted: Wed Apr 13, 2005 7:58 pm    Post subject: Reply with quote

I don't know what is wrong with your code, and I'm not debugging it for you.

I'm giving you this valuable information: when the {validator ...} tag is executed in the template, it isn't registered and it should be. That means somewhere in your code, you are displaying the template before the validator is registered. It is also possible that the validator gets mistakenly unregistered by a SmartyValidate::connect($smarty,true). Try putting debug statements in your code, follow the execution line by line until you figure out how this is happening. Sometimes it is helpful to dump out the $_SESSION and see what is happening during the submit cycle. Maybe start with an example that does work, and add code until it stops working.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    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