简体   繁体   中英

Update content of html file using JavaScript and PHP

I asked a similar question yesterday, but did not get a satisfactory answer to my question.

I found a solution. Just not sure what is the mistake in the new program.

In the following program, I first get the contents of the announcement.html and display it in the rich text editor. When the user edits the data in the rich text editor and clicks the submit button, the announcement.html needs to be updated, which is done by

file_put_contents('./inc/announcement.html',$data);

So actually when the submit button is clicked I want to run the get_editor_content() function and get the current content in the rich text editor and then send it to the php function and update the html file.

But it is not working. So what is my mistake?

<?php
    $temp= file_get_contents('./inc/announcement.html');
    require_once(the_class_name.'TinyMCEMaker.php');
    $richtext = new TinyMCEMaker('basic');
    $richtext->editor('Description', $temp);
?>

<form class="form" id="announcemnet" name="announcemnet" action="Announcemnet.php" method="post" onsubmit="return get_editor_content();">
    <input type="submit" onclick="get_editor_content()">
</form>

<script>
    function get_editor_content() {
        //method1 getting the content of the active editor
        var a = tinyMCE.activeEditor.getContent();
    }
</script>

<?php
    $data=$_GET['a'];
    file_put_contents('./inc/announcement.html',$data);
?>
I found the answer.
 <form action="Home.php" method="post" id="announcement">

    <?php

    $temp= file_get_contents('./path to html file');
    require_once(the_class_name.'TinyMCEMaker.php');
    $richtext = new TinyMCEMaker('basic');
    $richtext->editor('Description', $temp);
    ?>



      <input type="submit" name="formSubmit" value="Submit">

 </form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM