简体   繁体   English

使用JavaScript和PHP更新html文件的内容

[英]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. 在以下程序中,我首先获取announcement.html的内容,并将其显示在富文本编辑器中。 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 当用户在RTF编辑器中编辑数据并单击“提交”按钮时,需要更新announcement.html ,具体操作如下:

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. 因此,实际上,当单击提交按钮时,我想运行get_editor_content()函数并在RTF编辑器中获取当前内容,然后将其发送到php函数并更新html文件。

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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