ds111 Posted November 2, 2008 Share Posted November 2, 2008 Hey guys I am working on a project, and I have this feature to submit an article. Now, I want it so that when you start typing, every 10 seconds, it saves what you have so far to the database on a temporary table. That way, If your browser crashed, you just log in, go to the submit article page, and there is a link: "Saved Drafts (1)" or similar. you click that, and a popup window shows the titles and a brief preamble of what you've written when that draft was saved. I've looked ALL over the internet. There were like, 2 - -and they were very confusing and didnt work. One of em didnt save to a database, which I NEED it to save to the database. So, if anyone could help me out here, that would be awesome!! Thanks! Link to comment https://forums.phpfreaks.com/topic/131084-php-ajax-auto-save/ Share on other sites More sharing options...
corbin Posted November 2, 2008 Share Posted November 2, 2008 OK, you'll need to use set_timeout(), onkeypress (on the field in which users will be typing), AJAX and PHP. Learn basic PHP and AJAX. Set a listener for onkeypress on the typing field, and make it do "set_timeout('some_func', 10000);" function some_func() { //post data to PHP script to save //do it again in 10 seconds } Link to comment https://forums.phpfreaks.com/topic/131084-php-ajax-auto-save/#findComment-680615 Share on other sites More sharing options...
ds111 Posted November 2, 2008 Author Share Posted November 2, 2008 thanks. i know advanced PHP (im a very good PHP programmer, not trying to brag tho) but dont know much about Ajax. Any way you could please please help me with the Ajax part? THen I will put in my own PHP Code. thanks! Link to comment https://forums.phpfreaks.com/topic/131084-php-ajax-auto-save/#findComment-680633 Share on other sites More sharing options...
corbin Posted November 2, 2008 Share Posted November 2, 2008 If you were a very good PHP programmer, you could pick up the basics of AJAX in about 10 seconds. Just read some AJAX tutorials. Link to comment https://forums.phpfreaks.com/topic/131084-php-ajax-auto-save/#findComment-680766 Share on other sites More sharing options...
ds111 Posted November 7, 2008 Author Share Posted November 7, 2008 Ok well, I've made my own auto save script. But theres a problem. if i type some text, followed by TWO enters, then it doesnt save anything after the 2 enters. like so: test Test TEST! then only "test <br /> Test" will be saved. I am using tinyMCE as the rich text editor, and am doing a tinyMCE.save() before i $_POST the variables thru ajax to autosave.php. heres how the javascript of the main page with text editor looks like: function autosave() { var t = setTimeout("autosave()", 6700); tinyMCE.triggerSave(); var title = $("#title").val(); // var shortpost = $("#shortarticle").val(); var shortpost = document.getElementById("shortarticle").value; var fullpost = $("#fullarticle").val(); if (title.length > 0 || shortpost.length > 0) { $.ajax( { type: "POST", url: "autosave.php", data: "article_id=" + <?php echo $article_id; ?> + "&title=" + title + "&shortpost=" + shortpost + "&fullpost=" + fullpost, cache: false, success: function(message) { $("#timestamp").empty().append(message); } }); } } </script> note that: var shortpost = $("#shortarticle").val(); and var shortpost = document.getElementById("shortarticle").value; give the same results... autosave.php: <?php //include DB configuration file $noload = "yes"; include('registry.php'); connect_db(); $title = $_POST['title']; $shortpost = $_POST['shortpost']; $fullpost = $_POST['fullpost']; echo $fullpost; $id = (int)$_POST['article_id']; //save contents to database $query = "UPDATE `post_draft` SET title = '$title', shortpost = '$shortpost', fullpost = '$fullpost' WHERE id = '$id'"; $run_query = mysql_query($query); echo $query; //output timestamp echo '<div class="clean-ok">Auto Save system is ready. </div>'; ?> I echo the query, and it shows the problem -- it doesnt save after the 2 enters. so if anyone could help me out, then that would be totally awesome! Link to comment https://forums.phpfreaks.com/topic/131084-php-ajax-auto-save/#findComment-684243 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.