Posted By

LoRd1990 on 01/15/08


Tagged

errors javascript js php php5 Handling


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

luman
Nix


Show messages about errors using generating JavaScript.


 / Published in: PHP
 

URL: http://e-code.tnt43.com

  1. <?php
  2. class errors{
  3. private $_data='';
  4. private $_handlingStarted=0;
  5. private $_error=0;
  6.  
  7. function __construct()
  8. {
  9. $this->_data='<script type="text/javascript"><!--'."\n";
  10. $this->start();
  11. return true;
  12. }
  13.  
  14. function started(){
  15. return($this->_handlingStarted);
  16. }
  17.  
  18. function start(){
  19. $this->_handlingStarted=1;
  20. }
  21.  
  22. function isError(){
  23. return $this->_error;
  24. }
  25.  
  26. function appendJSError($text){
  27. if(!$this->started()) return ERRORS_STREAM_NSET;
  28. $this->_error=1;
  29. $this->_data.='alert("'.$text.'");'."\n";
  30. }
  31.  
  32. function redirect($url){
  33. if(!$this->started()) return ERRORS_STREAM_NSET;
  34. $this->_data.='window.location.href=\''.$url.'\';'."\n";
  35. }
  36.  
  37. function stopHandling()
  38. {
  39. $this->_data.='--></script>'."\n";
  40. }
  41.  
  42. function outputData()
  43. {
  44. if(!$this->started()) return ERRORS_STREAM_NSET;
  45. $this->stopHandling();
  46. return $this->_data;
  47. }
  48. }
  49. ?>

Report this snippet  

You need to login to post a comment.