best way to handle error messages?
| From: | paul at dostuff dot net | Date: | Sun, 15 Dec 2002 00:05:57 +0000 |
| Subject: | best way to handle error messages? | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-6797@lists.php.net to get a copy of this message | ||
Hi,
So say I have this script that is supposed to take input from $_POST and then verify that it meets some criteria. For this example, let's say that it must meet the following criterions:
1) must not be empty
2) must have eight or more characters (a password for instance)
If either one of these is not met, the script will return an error. Also, as an additional gotchya, I do not want any english language text in my script, so that if someone who did not speak english were to use my script, he or she could easily translate it without digging through PHP. What is the best way to handle this kind of situation using a template? The only solution I was able to come up with so far looked something like this:
test.php
--------
<?
if (empty($_POST["password"])) {
$error_code = 1;
} elseif (strlen($_POST["password"]) < 8) {
$error_code = 2;
} else {
// do some action as it passed all the filters
}
$smarty->assign("error_code",$error_code);
$smarty->display("test.tpl");
?>
test.tpl
--------
{ if isset($error_code) }
{if $error_code = 1}
You entered an empty password.
{ /if }
{if $error_code = 2}
Your password must be atleast eight characters long.
{ /if }
{ else }
{* no error code, so display the right page *}
{ /if }
However, this option seems to me to put way to much logic into the template. Is there some sort of switch statement I could use? Or is there another neat way to do this? Also, what if I want to do caching, or would caching this kind of situation be next to impossible?
Thanks,
Paul
--
Paul Lockaby
paul@dostuff.net
http://www.dostuff.net