ユーザーがテキストを変更したり画像を追加したりできる軽量の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のように動作する必要があります。いつものように、よろしくお願いします