จะเอาค่า GetContents(editorObj) จาก ckeditor มาใส่ตัวแปร php อย่างไร

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา จะเอาค่า GetContents(editorObj) จาก ckeditor มาใส่ตัวแปร php อย่างไร

จะเอาค่า GetContents(editorObj) จาก ckeditor มาใส่ตัวแปร php อย่างไร
<button onclick="alert(GetContents(editorObj));">แสดงข้อมูลใน CKEditor</button>

 



Thakachi 180.183.213.xxx 19-03-2011 16:44:40

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1

ผมไล่มาเป็นวันแล้ว..ใครก็ได้ช่วยหน่อนะครับ

จะเอาค่าจากโคดข้างบนมาใส่ในตัวแปร PHP เขียนยังไง

ขอบคุณครับ..(เว็บนี้ไม่มีผิดหวัง )



Thakachi 180.183.213.xxx 19-03-2011 16:46
 ความคิดเห็นที่ 2

ไฟล์ test.php
 

<!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="text/html; charset=utf-8" />

<title></title>
</head>

<body>
<SCRIPT language=javascript>
function formCheck(){
	alert(GetContents(editorObj));
}
</script>
<form name="editor_f" method="post" action="test.php" enctype="multipart/form-data">

<script type="text/javascript" src="cke_func.js"></script>
<?php
include_once("ckeditor/ckeditor.php");
include_once("cke_config.php");
$initialValue = '<p>This is some <strong>sample text</strong>.</p>'; // ค่าเริ่มต้น กรณีดึงข้อมูลมาแก้ไข
$CKEditor = new CKEditor();
// คืนค่าสำหรับใช้งานร่วมกับ javascript
$events['instanceReady'] = 'function (evt) { 
		return editorObj=evt.editor;
}';	
// บรรทัดด้านล่าง เปรียบได้กับการสร้าง textarea ชื่อ editor1 
// ตัวแปรรับค่า เป็น $_POST['editor1'] หรือ $_GET['editor1'] ตามแต่กรณี
$CKEditor->editor("editor1", $initialValue,$config,$events);
?>
 
<br />

<input type="submit" name="sub" value="Submit" />

<button onclick="InsertHTML('<p>แทรก  HTML</p>',editorObj);">แทรก  HTML</button>
&nbsp;
<button onclick="SetContents('<p>แทนที่ข้อความทั้งหมด</p>',editorObj);">แทนที่ข้อความทั้งหมด</button>
&nbsp;
<button onclick="alert(GetContents(editorObj));">แสดงข้อมูลใน CKEditor</button>
<?php
$txt_html="<script>GetContents(editorObj);</script>";
?>
</form>
</body>
</html>


 



Thakachi 180.183.213.xxx 19-03-2011 16:49
 ความคิดเห็นที่ 3

ค่าใน ckeditor ก็คือค่าจากตัวแปรชื่อ editor1 หรือฃื่อที่กำหนด
ถ้าส่งเป็น post ค่าก็จะอยู่ในตัวแปร $_POST['editor1']
ถ้าส่งเป็น get ค่าก็จะอยู่ในตัวแปร $_GET['editor1']

ส่วนที่ถามว่า เอาค่าจาก ckeditor มาใส่ตัวแปร php
ถามต่อว่า ถ้าได้ค่ามาอยู่ในตัวแปร จะทำอะไรต่อกับตัวแปร php



Ninenik 180.183.107.xxx 19-03-2011
 ความคิดเห็นที่ 4

ผมจะเอาลง text file ครับ

จะเอาค่าจาก alert(GetContents(editorObj)); ลงใน html.txt ครับ
พี่ลองเขียนตัวอย่างให้หน่อย..ผม

<?php
// การเขียนข้อมูลสู่ Text File
$f=fopen("ตำแหน่งของ File", "w");
fputs($f, ข้อมูลที่จะเขียนลง File);
fclose($f);
?> 

 



tawanc2005 180.183.190.xxx 19-03-2011 22:36
 ความคิดเห็นที่ 5

ค่าที่อยู่ในคำสั่ง alert(GetContents(editorObj))
ก็คือค่าเดียวกันกับค่าที่อยู่ใน ckeditor

ถ้าที่จะทำเป็น เป็นการ submit ข้อมูลไป โดยการกดปุ่ม Submit แล้วให้เอาค่าจาก
ค่าที่อยู่ใน ckeditor (  ค่าเดียวกันกับ ค่าที่อยู่ในคำสั่ง alert(GetContents(editorObj))  )
ก็ไม่จำเป็นต้องใช้ javascript หรือคำสั่ง GetContents(editorObj)
ให้เอาค่าจากชื่อ ckeditor ที่เรากำหนดไปใช้ได้ เพราะเป็นค่าเดียวกัน
จากที่จะเขียนไฟล์ พอกดปุ่ม submit รูปแบบโค้ดก็จะได้เป็น

<?php
// การเขียนข้อมูลสู่ Text File
$f=fopen("ตำแหน่งของ File", "w");
fputs($f, $_POST['editor1']);
fclose($f);
?> 

 

แต่ถ้าที่จะทำ ไม่ใช้การกดปุ่ม submit เพื่อส่งค่าข้อมูล เป็นเพียงการกดปุมคล้ายปุ่ม
<button onclick="alert(GetContents(editorObj));">แสดงข้อมูลใน CKEditor</button>  
แล้วให้เข้าข้อมูลไปบันทึก อันนี้คงต้องใช้ ajax แทน เช่น
ตัวอย่างไฟล์ทดสอบ

<button id="mybutton1" >แสดงข้อมูลใน CKEditor</button>  
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(function(){
	$("#mybutton1").click(function(){
		var data=GetContents(editorObj);
		$.post("write_file.php",{
			editor1:data
		},function(){
			alert("OK Complete.");
		});
	});
	// jQuery code
});
</script>

 

ตัวอย่างไฟล์เขียน write_file.php

 

<?php
if(isset($_POST['editor1'])){
	// การเขียนข้อมูลสู่ Text File
	$f=fopen("ตำแหน่งของ File", "w");
	fputs($f, $_POST['editor1']);
	fclose($f);	
}
?>

 



Ninenik 124.121.240.xxx 20-03-2011
 ความคิดเห็นที่ 6

สวัสดีครับคุณนิค

ส่งใสไปไล่โคดมากเกินเลยจำผิดๆ ทำให้ งง ไปเป็นวัน ผมไปใช้

if ( get_magic_quotes_gpc() )
		$postedValue = htmlspecialchars( stripslashes( $value ) ) ;
	else
		$postedValue = htmlspecialchars( $value ) ;

เห็นมันออก &lt;p&gt;
    This is some &lt;strong&gt;sample text&lt;/strong&gt;. You are using &lt;a href=&quot;http://ckeditor.com/&quot;&gt;CKEditor&lt;/a&gt;.&lt;/p&gt;

พอมาไล่ทำใหม่เริ่มใหม่หมด ถึงได้
 

<p>
	This is some <strong>sample text</strong>. You are using <a href="http://ckeditor.com/">CKEditor</a>.</p>

แต่มีข้อส่งสัยนิสหนึ่งเรื่องลง text file ค่าที่ได้มันไม่เหมือนกับที่ได้ตอนเอาลงฐานข้อมูล
ค่าใน txt มันจะมี ก่อน " ทุกที่เลยเท่าที่สังเกตุ ผมจึงเขียนฟังชั่น replace ค้นหา " แทนค่า "
 

<p>
	<img alt="indecision" src="http://localhost/ajaxckeditor/ckeditor/plugins/smiley/images/whatchutalkingabout_smile.gif" title="indecision" />Th<span style="color: rgb(255, 0, 0);">is is som</span>e <strong>sample text</strong>.</p>

แต่ค่าในฐานข้อมมูลมันปกติดี
 

<p>
	<img alt="indecision" src="http://localhost/ajaxckeditor/ckeditor/plugins/smiley/images/whatchutalkingabout_smile.gif" title="indecision" />Th<span style="color: rgb(255, 0, 0);">is is som</span>e <strong>sample text</strong>.</p>

เลยไม่เข้าใจทำมัยมันถึงมี ก่อน " ใน text file
วิธีเขียนก็เขียนตามที่พี่บอก

ขอบคุณครับ เว็บนี้มีสิ่งที่ดีๆมีประโยชน์ต่อผมมาก

 



Thakachi 180.183.213.xxx 20-03-2011 19:38
 ความคิดเห็นที่ 7

สังเกตรูปนะครับ แบล็คสแลช  มีใน text



Thakachi 180.183.213.xxx 20-03-2011 19:51
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ