Hi,
I'm a french student developper and i need of you today.
I would save my text after change.
Per exemple :
- I have my text with div id="editable" contenteditable="true"
- I change the text
- I save my new text
My dev :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="php/html" charset="iso-8859-1" />
<link rel="stylesheet" media="screen" type="text/css" title="index" href="index.css" />
<title>Accueil</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<script type="text/javascript" src="javascript/ckeditor/ckeditor.js"></script>
</head>
<body>
<div id="tete">
</div>
<div id="menu">
<?php
include("menu.php");
?>
</div>
<div id="corpsindex">
<div id="editable" contenteditable="true">
<h1>Inline Editing in Action!</h1>
<p>The div element that holds this text is now editable.
</div>
<script>
// Turn off automatic editor creation first.
CKEDITOR.disableAutoInline = true;
CKEDITOR.inline( 'editable' );
</script>
</div>
<div id="pied">
<?php
include("pied.php");
?>
</div>
</body>
</html>
Thanks !
Please ! :(
Please ! :(
Follow these steps. I use a
Follow these steps. I use a MySQL table called mybase to store the content you want to save (and perhaps reload) that I call mytext
Main document (you can call it main.php)
<!DOCTYPE html>
<title>Save inline stuff</title>
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<?php
//you must enter your own connexion details here
$host = 'host';
$dbuser = 'dbuser';
$dbpass = 'dbpass';
$dbname = 'dbname';
$dbconn = mysql_connect($host, $dbuser, $dbpass)
or trigger_error(mysql_error(), E_USER_ERROR);
mysql_select_db($dbname, $dbconn);
mysql_query("SET NAMES UTF8");
$query = mysql_query("SELECT mytext FROM mybase ");
$row = mysql_fetch_assoc($query);
$mytext = $row['mytext'];
echo "When you click outside the editing area after editing the content of the area is saved to the MySQL table<br><br>";
echo "<div style='border:2px solid;border-radius:25px;' id='mytext' contenteditable='true' onBlur='clickheretosave()'>" . $mytext . "</div>";
echo "<br>If you are successfull you should see that the <b>mytext</b> is also reloading when you hit F5";
?>
<script type='text/javascript' language='javascript'>
// <![CDATA[
function clickheretosave () {
var mytext = CKEDITOR.instances.mytext.getData();
$.post('mybase.php', {
mytext : mytext
})
}
// ]]>
</script>
</body>
</html>
In a separate file called mybase.php add the following code - you must of course fill in your own connection details for the database:
<?php header('Content-type: text/html; charset=UTF-8');
$host = 'host';
$dbuser = 'dbuser;
$dbpass = 'dbpass;
$dbname = 'dbname';
$dbconn = mysql_connect($host, $dbuser, $dbpass)
or trigger_error(mysql_error(), E_USER_ERROR);
mysql_select_db($dbname, $dbconn);
mysql_query("SET NAMES UTF8");
$sql = "UPDATE mybase SET mytext ='" . stripslashes($_POST['mytext']) . "'";
$queryresource = mysql_query($sql, $dbconn) or die(mysql_error());
?>
I have testet the code so it should work, but you need to create the database table also.