TinyMce和形式

问题描述

我正在尝试将TinyMCE与一种形式一起使用。我找到了一个有用的代码here,但它使用的数据库表只有一个字段。 我需要在数据库表中保存更多输入字段。我试图修改代码,但没有成功。

有人可以帮助我吗? 以下是主要代码:

<!DOCTYPE html>
<html>
 <head>
  <title>
   TinyMCE PHP MySQL Form
  </title>
  <script src="tinymce/tinymce.min.js"></script>
  <script>
  // (A) INIT TINYMCE
  // https://www.tiny.cloud/get-tiny/downloads/
  // https://www.tiny.cloud/docs/configure/
  tinymce.init({
    selector : '#contenuto',elements: "contenuto,num_sezione,num_modulo,consegna",plugins : "save",menubar : false,toolbar: 'save | styleselect | bold italic | alignleft aligncenter alignright alignjustify',save_onsavecallback : "save"
  });

  // (B) SAVE FUNCTION
  function save (editor) {
    // APPEND DATA
    var data = new FormData();
    data.append('contenuto',editor.getContent());
    /* ******* */
    // that's what I tried to do:
    data.append('num_sezione','num_sezione');
    data.append('num_modulo','num_modulo');
    data.append('consegna','consegnaì);
    /* ******* */
    // AJAX
    var xhr = new XMLHttpRequest();
    xhr.open('post',"3b-save.php",true);
    xhr.onload = function(){
      if (xhr.status==200) {
        var response = JSON.parse(this.response);
        alert(response.message);
      } else { alert("ERROR LOADING 3b-save.php!"); }
    };
    xhr.send(data);
  }
  </script>
</head>
<body>
<h2>Sample using TinyMCE and PHP</h2>
<form method="post">
<div class="row">
    <div class="col-xs-8">
     <div class="form-group">
      <label for="num_modulo">Modulo</label>
      <input id="num_modulo" class="form-control" name="num_modulo" type="text" value="Wall-E">
     </div>
     <div class="form-group">
      <label for="num_sezione">Sezione</label>
      <input id="num_sezione" class="form-control"  name="num_sezione" type="text" value="Sezione">
     </div>
    </div>
   </div>
   <div class="row form-group">
    <label for="consegna">Consegna</label>
    <input id="consegna" name="consegna"  type="text" value="Consegna">
    </div>
   </div>t
   <textarea id="contenuto" rows="15" cols="80"></textarea>
   </form>
 </div>
</body>
</html>

将数据发送到以下代码,在其中应将它们分开并发送到相应的sql表。

function add($text) {
  // add() : create a new content page
  // PARAM $aTesto : matrice con i valori del form?
  // here I need the value I have to save in a SQL table
  $sql="INSERT INTO `contents` (`contenuto`,) values(?)";
  
  try {
      $this->stmt = $this->pdo->prepare($sql);
      $this->stmt->execute([$text]);
      $this->lastID = $this->pdo->lastInsertId();
  } catch (Exception $ex) {
     $this->error = $ex->getMessage();
     return false;
  }
  $this->stmt = null;
  return true;
 }

我不想使用“提交”按钮,即我需要使用TinyMCE的保存选项。 有什么帮助吗? 提前致谢。 尼诺

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...