摘要:使用FckEditor
一個討論區如果沒有文字編輯器 就感覺太虛了
因此今天花2、3個小時去玩一下FckEditor這玩意
他支援的項目滿多的 有javascript、asp、asp.net等等
我今天只玩了javascript跟asp 不過都大同小異
今天我來介紹如何在ASP中使用FckEditor (官網也有介紹)
Step1:
首先一定要從官網下載
Step2:
將下載回來的壓縮檔解壓縮放於你網站的目錄(我是放在根目錄下面)
Step3:
在你的程式一開頭置入
<!-- #INCLUDE file="fckeditor/fckeditor.asp" -->
接著在<body>跟</body>之間隨便選一個位置放如下的程式碼
<%
Dim sBasePath
sBasePath = "fckeditor/"'Request.ServerVariables("PATH_INFO")
Dim oFCKeditor
Set oFCKeditor = New FCKeditor
oFCKeditor.BasePath = sBasePath
oFCKeditor.ToolbarSet = "UDefined"
oFCKeditor.Create "FCKeditor1"
%>
Dim sBasePath
sBasePath = "fckeditor/"'Request.ServerVariables("PATH_INFO")
Dim oFCKeditor
Set oFCKeditor = New FCKeditor
oFCKeditor.BasePath = sBasePath
oFCKeditor.ToolbarSet = "UDefined"
oFCKeditor.Create "FCKeditor1"
%>
醬子我們就大功告成了嗎?
不是的 這只完成了2/3
接著我們到form post的這一頁去接FCKeditor1的值
Dim sValue
sValue = server.HTMLEncode(Request.Form("FCKeditor1"))
sValue = server.HTMLEncode(Request.Form("FCKeditor1"))
完整程式如下
A.asp
<!--#INCLUDE file="fckeditor/fckeditor.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=big5"/>
<link rel="stylesheet" href="../all.css" />
</head>
<body>
<form id="form1" action="B.asp" method="post">
<%
Dim sBasePath
sBasePath="fckeditor/"
Dim oFCKeditor
Set oFCKeditor = New FCKeditor
oFCKeditor.BasePath = sBasePath
oFCKeditor.ToolbarSet = "UDefined"
oFCKeditor.Create "FCKeditor1"
%>
<input type="submit" value="Send" class="text2" onclick=""/>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=big5"/>
<link rel="stylesheet" href="../all.css" />
</head>
<body>
<form id="form1" action="B.asp" method="post">
<%
Dim sBasePath
sBasePath="fckeditor/"
Dim oFCKeditor
Set oFCKeditor = New FCKeditor
oFCKeditor.BasePath = sBasePath
oFCKeditor.ToolbarSet = "UDefined"
oFCKeditor.Create "FCKeditor1"
%>
<input type="submit" value="Send" class="text2" onclick=""/>
</form>
</body>
</html>
B.asp
<%
sValue = server.HTMLEncode(Request.Form("FCKeditor1"))
%>
sValue = server.HTMLEncode(Request.Form("FCKeditor1"))
%>
最後有3個問題點要處理
1、如果後端資料庫為SQL SERVER的話,其欄位型態要為text或ntext
2、在B.asp要處理html的字元,否則存進去會不是你想要的
因此我要在我的B.asp多做幾個工
sValue=replace(sValue,"<","<")
sValue=replace(sValue,">",">")
sValue=replace(sValue," ","")
sValue=replace(sValue,"&","&")
sValue=replace(sValue,""","""")
sValue=replace(sValue,"'","'")
sValue=replace(sValue,"§","§")
sValue=replace(sValue,"±","±")
sValue=replace(sValue,">",">")
sValue=replace(sValue," ","")
sValue=replace(sValue,"&","&")
sValue=replace(sValue,""","""")
sValue=replace(sValue,"'","'")
sValue=replace(sValue,"§","§")
sValue=replace(sValue,"±","±")
因為我這邊要處理上述的這些字元,所以我透過replace的function
經過如此的處理,我們就可以把sValue存進我們的資料庫了
3、我到現在還找不到如何防呆 我可以抓的到ID,可alert出來的ID是null=.=
所以我用比較笨的方法 在B.asp這一頁判斷,如果沒填 就return 回去請使用者填
最後,FCKEditor他是個open source,所以如果各位有哪邊想要改的,可以進去改
如我程式中的
oFCKeditor.ToolbarSet = "UDefined"
這個UDefined就是我自己定義的,因為我不想讓使用者看到太多功能 所以我就移除一些 呵
我應該只剩下上傳這邊還沒去玩他的功能 等日後有時間再來玩 呵