Saving tinymce textarea content to file

I have been trying to save tinymce editor textarea content to a .txt file for a while but without success yet.
This is my html file code:

<!Doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>TinyMCE example</title>
  <meta name="description" content="HTML5 Basic template">
  <meta name="author" content="R Dickinson">
  <link rel="stylesheet" href="css/styles.css?v=1.0">
  <script src="js/scripts.js"></script>
  <script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
  <script type="text/javascript">
tinyMCE.init({
// General options
mode : "textareas",

});
</script>
  <!--[if lt IE 9]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  <![endif]-->
</head>
<body>
    <header>
<h1>test tinymce save</h1>
    </header>
    <nav>
    </nav>
    <section>

<form method="post" action="test.php">
    <p> 
        <textarea name="content" style="width:50%"></textarea>
        <input type="submit" value="Save" />
    </p>     
</form>
    </section>
    <aside>
    </aside>
    <footer>
        </footer>
</body>
</html>

Now test.php

<?php
/*
 * test.php
  */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <title>test tiny mce</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <meta name="generator" content="Geany 0.21" />
</head>

<body>
<?php

echo(stripslashes($_POST['content']));
?>
<?php
$file = "data.txt";
$fp = fopen($file, 'w');
$data =(stripslashes($_POST['content']));
fwrite($fp, $data);
fclose($fp);
?>

</body>

</html>

I’m grateful for helpful replies to fix this-many thanks :-)

Update
Following the first answer below I have added triggerSave as:

 <script language="Javascript">
function submitForm() {
tinyMCE.triggerSave();
document.forms[0].submit();
}
</script>  

and

<form method="post" action="test.php">
<p> 
    <textarea name="content" style="width:50%"></textarea>
    <!--<input type="submit" value="Save" />-->
    <a href="javascript:submitForm();">Submit Form</a>
</p>     

but still no success…More help gratefully received

Leave a Reply

*

Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories