Re: [SMARTY] eval in smarty

From: Date: Wed, 14 Mar 2007 00:38:05 +0000
Subject: Re: [SMARTY] eval in smarty
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-13691@lists.php.net to get a copy of this message
Hi. Assigned content is not itself treated as template text. Thus, it is not parsed by Smarty. Your options are to either i) assign actual content; ii) use {eval} in your template; iii) create a custom resource to load your config data. Smarty parses text returned from resources as expected. The seciond option is the worst overall (for a variety of reasons including performance) so it should be used only as a last resort, IMO. boots --- Wiwid Lukiyanto <wiwid-l@centrin.net.id> wrote: > Hi, I'm Wiwid, new member on here. > > I have the problem about eval function on smarty. Maybe someone can help me? > OK, I explain the code: > > ************************************************************************ > english.conf: > ************************************************************************ > register = "Register" > username = "Username" > password = "Password" > password_confirm = "Password Confirmation" > submit = "Submit" > > register_success = "Registration success" > inputs_empty = "Please fill all the fields" > password_not_match = "Password and password confirmation not match" > > ************************************************************************ > function.php: > ************************************************************************ > class Customer { > > function register() { > > if(!empty($_POST['username_register']) && > !empty($_POST['password_register']) && > !empty($_POST['password2_register']) && > ($_POST['password_register'] == > $_POST['password2_register'])) { > > $command = "INSERT INTO customer SET > username = > '".$_POST['username_register']."', > password = > MD5('".$_POST['password_register']."')"; > $query = mysql_query($command) > or die("Can't insert registration data : " . mysql_error()); > > $message = "#register_success#"; > > } else if($_POST['password_register'] != $_POST['password2_register']) { > > $message = "#password_not_match#"; > > } else { > > $message = "#inputs_empty#"; > > } > > return $message; > > } > > } > > ************************************************************************ > register.php: > ************************************************************************ > require_once("config.php"); // assumed database already connected from > config.php > require_once("function.php"); > > $smarty->config_load("english.conf"); > > $customer = new Customer; > > if(isset($_POST['username_register'])) { > > $message = $customer->register(); > $smarty->assign("message", $message); > > } > > ************************************************************************ > register.tpl: > ************************************************************************ > {if $smarty.post.username_register != ""} > > <table border="1" width="390"> > <tr> > <td align="left" colspan="2">{eval var=$message}</td> > </tr> > </table> > {/if} > <table border="1" width="390"> > <form action="{$smarty.server.PHP_SELF}" method="post"> > <tr> > <td align="left" colspan="2">{#register#}</td> > </tr> > <tr> > <td align="left">{#username#}</td> > <td align="left"><input type="text" > name="username_register" > value="{$smarty.post.username_register}" /></td> > </tr> > <tr> > <td align="left">{#password#}</td> > <td align="left"><input type="password" > name="password_register" /></td> > </tr> > <tr> > <td align="left">{#password_confirm#}</td> > <td align="left"><input type="password" > name="password2_register" > /></td> > </tr> > <tr> > <td align="right" colspan="2"><input type="submit" > name="submit" > value="{#submit#}" /></td> > </tr> > </form> > </table> > ************************************************************************* > > When register.php run, I want the "message" text appear with one of these > text: > > Registration success > Please fill all the fields > Password and password confirmation not match > > But I find the text appear as one of these: > > #register_success# > #inputs_empty# > #password_not_match# > > That's it. > Thank you for help me. ____________________________________________________________________________________ Need Mail bonding? Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users. http://answers.yahoo.com/dir/?link=list&sid=396546091

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