clsharpe

drafts

Nov 5th, 2014
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. main file:
  2.  
  3. at top: <?php
  4. if($_GET['draft']==1){
  5. $draft=1;
  6. $filepath = "drafts/draft.dat";
  7. $msg = file_get_contents($filepath);
  8. }
  9. ?>
  10.  
  11. in header: <script src="myscripts.js"></script>
  12.  
  13. in body: <textarea id="msg" name="writing" cols="55" rows="7"><?php if($draft==1){ echo $msg; } ?></textarea><input type="submit" value="Post it"/> <a href="#" onclick="sendMsg()">Save draft</a> | <a href="home.php?draft=1">Load draft</a>
  14.  
  15. javascript file (myscripts.js)
  16.  
  17. function sendMsg()
  18. {
  19. var str = document.getElementById("msg").value;
  20. document.getElementById("msg").value = "Draft saved!";
  21. showHint(str);
  22. document.getElementById('chatframe').contentWindow.location.reload()
  23. }
  24. function showHint(str)
  25. {
  26. var xmlhttp;
  27. if (str.length==0)
  28. {
  29. document.getElementById("txtHint").innerHTML="";
  30. return;
  31. }
  32. if (window.XMLHttpRequest)
  33. {// code for IE7+, Firefox, Chrome, Opera, Safari
  34. xmlhttp=new XMLHttpRequest();
  35. }
  36. else
  37. {// code for IE6, IE5
  38. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  39. }
  40. xmlhttp.onreadystatechange=function()
  41. {
  42. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  43. {
  44. document.getElementById("msg").innerHTML="";
  45. }
  46. }
  47. xmlhttp.open("GET","savedraft.php?q="+str,true);
  48. xmlhttp.send();
  49. }
  50.  
  51. savedraft.php file
  52.  
  53. <?php
  54. $msg=$_GET['q'];
  55. $filepath = "drafts/draft.dat";
  56. file_put_contents($filepath,$msg);
  57. ?>
Advertisement
Add Comment
Please, Sign In to add comment