Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main file:
- at top: <?php
- if($_GET['draft']==1){
- $draft=1;
- $filepath = "drafts/draft.dat";
- $msg = file_get_contents($filepath);
- }
- ?>
- in header: <script src="myscripts.js"></script>
- 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>
- javascript file (myscripts.js)
- function sendMsg()
- {
- var str = document.getElementById("msg").value;
- document.getElementById("msg").value = "Draft saved!";
- showHint(str);
- document.getElementById('chatframe').contentWindow.location.reload()
- }
- function showHint(str)
- {
- var xmlhttp;
- if (str.length==0)
- {
- document.getElementById("txtHint").innerHTML="";
- return;
- }
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)
- {
- document.getElementById("msg").innerHTML="";
- }
- }
- xmlhttp.open("GET","savedraft.php?q="+str,true);
- xmlhttp.send();
- }
- savedraft.php file
- <?php
- $msg=$_GET['q'];
- $filepath = "drafts/draft.dat";
- file_put_contents($filepath,$msg);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment