I'm trying to build an interface to insert, edit and delete records in a MySQL database, using PHP and a TinyMCE editor to insert rich text.
When I try to populate the fields in the form in the "edit" section, the TinyMCE text areas don't work. The text inputs are correctly populated with the database data, but the text areas remain empty.
I already tried to reset the TinyMCE init (I need to disable paragraphs), but nothing changes.
Here's the code of my edit page:
<html>
<head>
<script type="text/javascript" src="tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
forced_root_block : "",
force_br_newlines : true,
force_p_newlines : false
});
//validator form js
function validate_form(){
var x = document.getElementById('autore').value;
var y = tinyMCE.get('titolo').getContent();
if( x == "" || x == null || y == "" || y == null){
alert("Inserisci autore e titolo");
return false;
}
}
</script>
</head>
<body>
<?php
include ("connessione_mysql.php");
$rows_id=$_GET["rows_id"];
$sql="SELECT * FROM bibliografia WHERE ID='$rows_id'";
$results=mysql_query($sql, $connessione_mysql);
$num_rows=mysql_num_rows($results);
if ($num_rows==0) {
echo "Il database è vuoto";
} else {
while ($rows=mysql_fetch_array($results)) {
$autore =$rows['autore'];
$titolo=$rows['titolo'];
$note=$rows['note'];
$editore=$rows['editore'];
$ID=$rows['ID'];
}
echo "<form method='post' onsubmit='return validate_form()' action='script2_modifica_bibliografia.php' class='dark-matter'>";
echo "<label><span>Autore* :</span> <INPUT TYPE=\"TEXT\" NAME=\"autore\" id=\"autore\" VALUE=\"$autore\" SIZE=\"74\"></label>";
echo "<label><span>Titolo* :</span><div class=\"aggiusta\"><TEXTAREA NAME=\"titolo\" id=\"titolo\" VALUE=\"$titolo\" ROWS=\"10\" COLS=\"60\"></TEXTAREA></div></label><br>";
echo "<label><span>Note :</span><div class=\"aggiusta\"><TEXTAREA NAME=\"note\" VALUE=\"$note\" ROWS=\"10\" COLS=\"60\"></TEXTAREA></div></label><br>";
echo "<label><span>Editore :</span> <INPUT TYPE=\"TEXT\" NAME=\"editore\" VALUE=\"$editore\" SIZE=\"74\"></label>";
echo "<input type=\"hidden\" name=\"ID\" value=\"$ID\">";
echo "<label><span> </span><INPUT TYPE=\"SUBMIT\" VALUE=\"Modifica il record\" CLASS=\"SUBMIT\"></label>";
}
echo "</FORM>";
mysql_close($connessione_mysql);
?>
</body>
</html>