0

ユーザーがテキストを変更したり画像を追加したりできる軽量のCMSシステムを開発しています。form.textareaを使用することを望んでいましたが、残念ながらtextareaはHTMLタグを許可していません。少なくとも、画像タグは許可していません。そこで、フォーム入力をtextareaからdivに変更しました。私の質問は、textareaが機能するのと同じように、divの内容をPOST変数としてPHPスクリプトに簡単に渡す方法です。

コードスニペットを次に示します。HTMLヘッドで、このJQueryを使用して、画像アイコン(imgBtn)がクリックされたときにdivコンテンツに画像コードを追加します。

 <script language="javascript" type="text/javascript">
   $("#imgBtn").live("click",function(){
     var path = "path/to/file.jpg";
     var imgcode = '<img src="' + path + '" alt="User Image">';
 $('.textarea').append(imgcode);
});
 </script>

次に、HTML本文の後半で、このPHPを使用して初期DIVを生成するか、filewrite()クラスを介して新しいデータをテキストファイルに書き込みます。

 <?php
 if ($submit==true){    //$_POST['submit']
 $string = $text;       //$_POST['text'] this is where I need the POST text
 $flag=HTML;
 $scrubstring = sanitize($string,$flag,2,1200); //cleans input
 $scrubstring = trim($scrubstring);
    if ($scrubstring){
    //scrubber returns true, write text to the file.
$filewrite = new filewrite();
    //path (from root dir),string to write
$filewrite->writer("aboutus/".$file,$scrubstring);
    }
      echo '<div contenteditable="true" class="textarea">';
  echo $scrubstring.'</div>';
}else{
  $fread = new filewrite(); //instantiate the class
  $output=explode(",",$fread->readlastline($file));
  echo '<div contenteditable="true" class="textarea">';
  echo $output[1].'</div>';
    }
   ?>

つまり、div「textarea」がtextareaのように動作する必要があります。いつものように、よろしくお願いします

4

1 に答える 1

0
<script type="text/javascript">
$(function() {
  $('#form').submit(function(){
    $('#txa').val($('#content').html());
  });
});
</script>

<?php
  echo $_POST['txa'];
?>


<div id="content">
  <h1>abcde</h1>
</div>

<form method="post" action="?" id="form">
  <input type="hidden" name="txa" id="txa" value="123" />
  <input type="submit" />
</form>
于 2012-12-11T00:30:28.737 に答える