Hej jeg har en richtexteditor jeg prøver at få til at virke men den kommer kun til kan ikke gemme det
html kode
- <form action="index.php?add" method="post" enctype="multipart/form-data">
- <div><label for="title">Title *</label> <input type="text" name="title" id="title" /></div>
- <input type="button" onClick="iBold()" value="B">
- <input type="button" onClick="iUnderline()" value="U">
- <input type="button" onClick="iItalic()" value="I">
- <input type="button" onClick="iFontSize()" value="Text Size">
- <input type="button" onClick="iForeColor()" value="Text Color">
- <input type="button" onClick="iHorizontalRule()" value="HR">
- <input type="button" onClick="iUnorderedList()" value="UL">
- <input type="button" onClick="iOrderedList()" value="OL">
- <input type="button" onClick="iLink()" value="Link">
- <input type="button" onClick="iUnLink()" value="UnLink">
- <input type="button" onClick="iImage()" value="Image">
- <div><label for="info">Artikel info *</label></div>
- <div><textarea style="width:400px; display:none; height:60px; max-height:200px; color:#000;" name="info" id="info"></textarea><iframe name="richTextField" id="richTextField" style="border:#000000 1px solid; width:700px; height:300px;"></iframe></div>
- <div><input type="file" name="fil" /></div>
- <div><input name="sub" type="button" value="Submit Data" onClick="javascript:submit_form();"/></div>
- </form>
js kode
- <script type="text/javascript">// This is a javascript file named wysiwyg.js
- function iFrameOn(){
- richTextField.document.designMode = 'On';
- }
- function iBold(){
- richTextField.document.execCommand('bold',false,null);
- }
- function iUnderline(){
- richTextField.document.execCommand('underline',false,null);
- }
- function iItalic(){
- richTextField.document.execCommand('italic',false,null);
- }
- function iFontSize(){
- var size = prompt('Enter a size 1 - 7', '');
- richTextField.document.execCommand('FontSize',false,size);
- }
- function iForeColor(){
- var color = prompt('Define a basic color or apply a hexadecimal color code for advanced colors:', '');
- richTextField.document.execCommand('ForeColor',false,color);
- }
- function iHorizontalRule(){
- richTextField.document.execCommand('inserthorizontalrule',false,null);
- }
- function iUnorderedList(){
- richTextField.document.execCommand("InsertOrderedList", false,"newOL");
- }
- function iOrderedList(){
- richTextField.document.execCommand("InsertUnorderedList", false,"newUL");
- }
- function iLink(){
- var linkURL = prompt("Enter the URL for this link:", "http://");
- richTextField.document.execCommand("CreateLink", false, linkURL);
- }
- function iUnLink(){
- richTextField.document.execCommand("Unlink", false, null);
- }
- function iImage(){
- var imgSrc = prompt('Enter image location', '');
- if(imgSrc != null){
- richTextField.document.execCommand('insertimage', false, imgSrc);
- }
- }
- function submit_form(){
- var theForm = document.getElementById("myform");
- theForm.elements["info"].value = window.frames['richTextField'].document.body.innerHTML;
- theForm.submit();
- }</script>
php kode
- if ($_POST['sub']) {
- $title = htmlentities($_POST['title']);
- $info = nl2br(trim($_POST['richTextField']));
-
- $name = $_FILES['fil'] ['name'];
- $type = $_FILES['fil'] ['type'];
- $size = $_FILES['fil'] ['size'];
- $tmp = $_FILES['fil'] ['tmp_name'];
- $ext = substr($name, strrpos($name, '.'));
-
- if ($title && $info) {
- $dag = date('Y-m-d H:i:s');
-
- if ($name) {
- move_uploaded_file ($_FILES['fil'] ['tmp_name'], "./content/$title.$ext");
-
- $fil = "$title$ext";
- }
-
- mysql_query("INSERT INTO `a`(`id`, `title`, `info`, `dag`, `fil`) VALUES ('','$title','$info','$dag','$fil')");
-
- echo 'Din artikel er oprettet';
- } else {
- echo 'Du skal udfylde alle felter med *';
- }
- }