Re: How do I output error messages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, February 21, 2006 12:52 pm, Paul Goepfert wrote:

$messages = array();

> if (isset($submit))
> {
>   //vaildation code

Each invalid input adds another element to $messages array.
    //E.G.:
    if (!isset($_REQUEST['name'])) $messages[] = "Name is a required
field.";

> }
> else
> {

if (count($messages)){
  echo "<p class=\"error\">", implode("<br />\n", $messages), "</p>\n";
}

> //webpage
> }

You still need to take care that the //webpage itself is not made
insensible by the error conditions...

In extreme cases, such as the database being down and there being no
hope of the rest of the page being useful, I sometimes will do:

if (!$connection){
  head("Error"); //This prints out masthead/navbar etc
  $messages[] = "Unable to access database. Please try later.";
  echo "<p class=\"error\">", implode("<br />\n", $messages), "</p>\n";
  foot(); //This closes all HTML tags from head()
  //both head and foot are defined in a single include file,
  //making it trivial to match up HTML open/close tags
}

It's not as "slick" as some CRM setups, but it's also not as
cumbersome and over-engineered (imho).

DSFDF

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux