Wysiwyg Beispiel von hier, wie geänderten Text im Formular anzeigen ?

newbie84

Grünschnabel
Hallo zusammen,
bei der Suche nach einer Wysiwyg Lösung habe ich hier ein sehr schönes Beispiel gefunden und möchte das gerne weiter Bearbeiten.

Ich habe das Beispiel um eine Funktion erweitert, die den Text in eine Php Datei speichert...soweit so gut :)

Nun möchte ich aber den geänderten Text auch in diesem Formular anzeigen und das funktioniert leider nicht so leicht wie gedacht.

Wäre jemand bitte so nett mir zu zeigen woran es liegt oder mir einen Denkanstoss zu geben ?

$test_text1 ist der geänderte Text und wird im Formular nicht angezeigt :confused:

Code:
$test_text1 = "<span style=\"font-weight: bold;\">test</span>"; // das geht nicht << warum 
$test_text2 = "test";    // das ist der starttext vor der änderung


Hier das Funktionierende Php Beispiel:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>Verbessertes Eingabefeld (WYSIWYG-Editor)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
	.imagebutton {
		width: 20px;
		height: 20px;
		border: 0px;
		border-color: #FF0000;
		display: inline; }
	#edit {
		border: solid 1px #CDCDCD; }
	a {
		text-decoration:none; }
	a:hover {
		color: #33FFFF; }
	a:visitied {
		color:#0000FF;
	}
</style>
<script type="text/javascript"><!--
	//coded by con-f-use@gmx.net - be fair and do not remove this

	var	formu, ifrm, uagent=navigator.userAgent.toLowerCase(),
		isGecko = ( uagent.match('gecko') && navigator.productSub>=20030210 ),
		isIE = uagent.match('msie') && !uagent.match('opera') && (!uagent.match('msie 5.5')||!uagent.match('msie 6.'));

	function initEdit(strFormu,strEdit,strDefTxt) {
		formu = document.getElementById(strFormu);
		if (isIE)
			ifrm = window.frames[strEdit].document;
		if (isGecko)
			ifrm = document.getElementById(strEdit).contentWindow.document;
		ifrm.designMode = 'on';
		if (strDefTxt)
			with (ifrm) {
				open();
				write(strDefTxt);
				close();
			}
		var kids = document.getElementsByTagName('div');
		for (i in kids)
			if (kids[i].className == 'imagebutton')
				kids[i].onclick = tbclick;
		document.getElementById(strEdit).contentWindow.focus();
	}

	function tbclick() {
		var id = this.id;
		if (id == 'CreateLink' && isIE)
			ifrm.execCommand(id);
		else {
			if (id=='FontName' || id=='FontSize') {
				sel = document.getElementById(id).childNodes;
				sel = isIE ? sel[0] : sel[1];
				arg = sel.options[sel.selectedIndex].firstChild.data; }
			else if (id == 'InsertImage')
				arg = prompt('Enter a image location:', 'http://');
			else if (id == 'CreateLink')
				arg = prompt('Enter a URL:','http://');
			else
				arg = null;
			ifrm.execCommand(id,false,arg);
		}
	}

	function processData() {
		formu.content.value = ifrm.body.innerHTML;
  		if( !formu.content.value.replace(/<br>|\s|&nbsp;/ig,'') ) {
			alert('You did not enter any Text!');
			return false;
		}
                formu.txtcontent.value=formu.content.value;
		return true;
	}
//--></script>
</head>


<?php
   // kleiner testtext...später text aus datei
   $test_text1 = "<span style=\"font-weight: bold;\">test</span>"; // das geht nicht << warum 
   $test_text2 = "<b>test</b>";    // das geht text ist fett
   $test_text3 = "test";           // das geht text ist normal

   // php code zum speichern erstellen
   $php_Code  = "<?php echo \"";
   $php_Code .= $txtcontent;
   $php_Code .= "\"; ?>";

   // php code speichern
   $fp = fopen ('test.php' , "w");   // Datei öffnen
   fwrite ($fp , $php_Code);        // Dateiinhalt in die Datei schreiben
   fclose ($fp);                    // Datei schließen

   // richedit mit text aus variable füllen
   echo "<body onload=\"initEdit('form_content','edit','{$test_text1}')\">";
?>






<div style="position: absolute; left: 10px; top: 10px;">

<form onsubmit="return processData()" name="main" id="form_content" action="" method="post"><div>
<input type="hidden" name="txtcontent">


	<div class="imagebutton" id="FontSize">
		<select>
			<option>1</option>
			<option>2</option>
			<option selected="selected">3</option>
			<option>4</option>
			<option>5</option>
			<option>6</option>
			<option>7</option>
	   </select>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="FontName">
		<select>
			<option>Arial</option>
			<option selected="selected">Times New Roman</option>
			<option>Comic Sans MS</option>
		</select>
	</div><br>

	<div class="imagebutton" id="bold">
		<a href="#" onclick="return false" style="font-weight: bold;">B</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="italic">
		<a href="#" onclick="return false" style="font-style: italic;">I</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="underline">
		<a href="#" onclick="return false" style="text-decoration: underline;">U</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="justifyleft">
		<a href="#" onclick="return false">left</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="justifycenter">
		<a href="#" onclick="return false">center</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="justifyright">
		<a href="#" onclick="return false">right</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="insertorderedlist">
		<a href="#" onclick="return false">odered list</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="insertunorderedlist">
		<a href="#" onclick="return false">unordered list</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="CreateLink">
		<a href="#" onclick="return false">link</a>
	</div><br>

	<div class="imagebutton" id="indent">
		<a href="#" onclick="return false">indent</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="outdent">
		<a href="#" onclick="return false">outdent</a>
	</div>&nbsp;&nbsp;

	<div class="imagebutton" id="InsertImage">
		<a href="#" onclick="return false">insert image</a>
	</div>

	<br>
         <iframe id="edit" name="edit" marginheight="0" marginwidth="0" frameborder="0" height="200" width="400"></iframe>
	<textarea name="content" style="display: none;"></textarea>

	<div style="width: 400px;" align="right">
		<input value="Submit!" type="submit">
	</div>
</div></form>

</div>

</body></html>

Vielen Dank
 
Zurück