Home > Archive > PHP Smarty Templates > July 2007 > Re: [SMARTY] eval in smarty
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: [SMARTY] eval in smarty
|
|
| boots 2007-03-13, 10:11 pm |
| 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
| |
|
|
|
|
|
|
|
|
|
|
|