3 Replies - 432 Views - Last Post: 01 February 2011 - 11:24 AM Rate Topic: -----

#1 PhunkRabbit  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 81
  • View blog
  • Posts: 406
  • Joined: 23-August 10

Best way to process and display validation and general errors to users

Posted 01 February 2011 - 09:46 AM

I am currently working on a system that is basically a stripped down CRM.

When the user performs an action that causes an error I dont want to just echo the error message as it happens in the code.

I came up with a simple function that would process my errors and wrap them with a paragraph and relevant css class. Unfortunatly it seems that I am only able to then display all these errors at the bottom of the page (end of the script) then position them using CSS where I want them using CSS positioning (yuck!).

I am not happy with this way of processing my errors and after putting in a couple of hours work on it last night am starting to get annoyed trying to think of another way to do it.

This is a really simplified version of what ive been doing (from memory, bere with me).

<?php
function errorStack($error,$type = '1'){
     if($type == '1'){
          $msg = '<p class="error">' . $error . '</p>';
     }else{
          $msg = '<p class="info">' . $error . '</p>';
     }
     return $msg;
}

$myerror = 'Oops! Sorry there seems to have been an error.';
$stack .= errorStack($myerror);
?>



//end of all PHP code.
<div id="errorstack">
<?php
echo $stack;
?>
</div>
</body>
</html>



I am sure I have overlooked somthing.

  • How do you process your errors for display to the user?
  • Standard form validation errors are fine for now since they echo above or next to the form field in question.
  • Is putting all the errors into a function to be processed overkill in your opinion?
  • Am I over complicating the thought process?


Thanks guys

Is This A Good Question/Topic? 0
  • +

Replies To: Best way to process and display validation and general errors to users

#2 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Best way to process and display validation and general errors to users

Posted 01 February 2011 - 10:36 AM

Personally, I use a custom exception handler and I have an error page template loaded in my template engine in case of errors. If an exception is thrown, they see the error page with relevant information regarding the error they experienced (usually some sort of generic message like "There was an error with the database. It has been logged." with a link to go back or something). If everything runs smoothly, they see the page they were attempting to access. To me, it's clean, elegant, and really quite simple. And that's just the way I like it :)

EDIT: Regarding form validation errors, I usually set an error conditional in my template. If there's a validation error, I set it to have a value, and the template has logic such that if it sees a value in that tag, it displays the error element with the information inside.

This post has been edited by Valek: 01 February 2011 - 10:37 AM

Was This Post Helpful? 1
  • +
  • -

#3 PhunkRabbit  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 81
  • View blog
  • Posts: 406
  • Joined: 23-August 10

Re: Best way to process and display validation and general errors to users

Posted 01 February 2011 - 10:56 AM

View PostValek, on 01 February 2011 - 05:36 PM, said:

Personally, I use a custom exception handler and I have an error page template loaded in my template engine in case of errors. If an exception is thro...
...mplate has logic such that if it sees a value in that tag, it displays the error element with the information inside.


Thanks Valek,

I didn't want to have to go down the road of templates since the system is so stripped down however I will certainly consider it.

I am still interested if anyone has differing opinions or thoughts.
Was This Post Helpful? 0
  • +
  • -

#4 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 543
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: Best way to process and display validation and general errors to users

Posted 01 February 2011 - 11:24 AM

Well, really, it's not as bad as you might think. You can do a very rudimentary template system and still have it incredibly lightweight. Smarty is quite bulky, but I rolled my own based on phpBB's templating engine and I've never looked back.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1