Show messages about errors using generating JavaScript.


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  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. ?>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.