2017-11-01 2 views
0

CKEditor를 사용하고 있는데 데이터베이스에 업로드하는 데 문제가 있습니다. 우선 textarea id (나는 텍스트 마디 name을 사용하지만 id을 사용하고 싶지 않습니다.) 값을 숨겨진 입력 값으로 지정하고 싶습니다.데이터베이스에 텍스트 영역 값을 삽입하는 방법은 무엇입니까?

HTML & JQuery와 (test.php)

<!DOCTYPE html> 
<html> 
<head> 
    <!-- CKEditor full package v4.7.3 --> 
    <script type="text/javascript" src="ckeditor/ckeditor.js"></script> 
    <!-- Jquery --> 
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
</head> 
<body> 
    <form action="test2.php" method="POST" target="_blank"> 
     <textarea id="description-down1"></textarea> 
     <script type="text/javascript">CKEDITOR.replace("description-down1")</script> 
     <br><br> 
     <input type="submit" name="save-button" value="Insert"> 
     <!-- #3 take the value via name into php --> 
     <input type="hidden" name="insert-variable-value-name" id="insert-variable-value-id"> 
    </form> 
    <script type="text/javascript"> 

     $(document).ready(function(){ 

      //#1 take value from textarea "id" 
      var data = // what code write here? 

      //#2 put the value of textarea into hidden input 
      document.getElementById('insert-variable-value-id').value = data; 

     }); 

    </script> 
</body> 
</html> 

PHP (test2.php)

<?php 
    //connection 
    $conn = new mysqli("localhost", "root", "", "test_engine"); 

    // call the value from the hidden input 
    $description = $_POST['insert-variable-value-name']; 

    // Insert data 
    $insert_data = "INSERT INTO test (description) 
        VALUES('$description')"; 
    $conn->query($insert_data); 
?> 
당신은 숨겨진 입력 값을 설정 remeber 필요
+2

에 오신 것을 환영합니다! [투어] (https://stackoverflow.com/tour)를 방문하여 질문을 편집하여 잘못된 결과와 일부 샘플 데이터로 원하는 결과를 모두 표시하십시오. –

답변

0
var data = CKEDITOR.instances['description-down1'].getData(); 

양식을 제출하거나 일부 간격으로 해당 필드를 업데이트하기 전에.

0

감사합니다. Bart에게 도움을 요청합니다. 나는 here 답을 찾는다. 먼저 코드를 실행 한 다음 제출하십시오.

Previus 코드 :

<body> 
    <form action="test2.php" method="POST" target="_blank"> 
     <textarea id="description-down1"></textarea> 
     <script type="text/javascript">CKEDITOR.replace("description-down1")</script> 
     <br><br> 
     <input type="submit" name="save-button" value="Insert"> 
     <!-- #3 take the value via name into php --> 
     <input type="hidden" name="insert-variable-value-name" id="insert-variable-value-id"> 
    </form> 
    <script type="text/javascript"> 

     $(document).ready(function(){ 

      //#1 take value from textarea "id" 
      var data = // what code write here? 

      //#2 put the value of textarea into hidden input 
      document.getElementById('insert-variable-value-id').value = data; 

     }); 

    </script> 
</body> 

편집 코드 : 스택 오버플로

<body> 
    <!-- Create form id='form-id' --> 
    <form action="test2.php" method="POST" target="_blank" id='form-id'> 
     <textarea id="description-down1"></textarea> 
     <script type="text/javascript">CKEDITOR.replace("description-down1")</script> 
     <br><br> 
     <!-- Create submit id='save-button' --> 
     <input type="submit" name="save-button" value="Insert" id='save-button'> 
     <!-- #3 take the value via name into php --> 
     <input type="hidden" name="insert-variable-value-name" id="insert-variable-value-id"> 
    </form> 
    <script type="text/javascript"> 

     $(document).ready(function(){ 

      $('#save-button').click(function(e){ 

       //Stop 
       e.preventDefault(); 

       //The code 

       //#1 take value from textarea "id" 
       var data = CKEDITOR.instances['description-down1'].getData(); 

       //#2 put the value of textarea into hidden input 
       document.getElementById('insert-variable-value-id').value = data; 

       //Proceed the submit 
       $('#form-id').submit(); 

      }); 

     }); 

    </script> 
</body> 
관련 문제