0

developing a light weight CMS system where users are able to change text and add an image. Was hoping to use form.textarea, unfortunately textarea doesn't allow HTML tags, at least not image tag. So I've changed the form input to div from textarea. My question is how can I easily pass the div contents to a PHP script as a POST variable, similar to how the textarea would work.

Here are some code snippets: In the HTML head, using this JQuery to append the image code when to the div content when an image icon (imgBtn) is clicked.

 <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>

Then later in the HTML body, using this PHP to generate the initial DIV or write the new data to a text file via the filewrite() class.

 <?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>';
    }
   ?>

So in short, I need the div "textarea" to behave like a textarea. As always, thank you in advance

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 回答