稍微改了改網上的一個ASP+XML的簡易留言本

來源:互聯網
上載者:User

 

<?xml version="1.0" encoding="gb2312"?>
<GuestBook version="1.0" realese="2060107">
 <Record>
  <Name>KAI</Name>
  <Email>kai@hostx.org</Email>
  <Url>http://www.17xml.com </Url>
  <Content>千山萬水總是情,常來泡妞行不行?哢哢:_)</Content>
  <Time>2006-1-7 11:15:47</Time></Record><Record><Name>jkh</Name><Email>mnmk</Email><Url>kkkii</Url><Content>iuuhhhhhhhh</Content><Time>2006-1-7 11:19:32</Time></Record></GuestBook>

<%@Language="VBScript"%>

<!--#include file="def.asp"-->
<!--#include file="htmlhead.asp"-->
<%
'設定Web頁面的資訊
Response.Buffer = true
Response.Expires = -1

'顯示留言函數init()
'www.knowsky.com
Function init()
entryForm()
 
'定義局部變數
Dim objXML
Dim arrNames
Dim arrEmails
Dim arrURLS
Dim arrMessages
 
'建立XMLDOM文檔對象,用來存放留言
Set objXML = server.createObject("Msxml2.DOMDocument")
objXML.async = false
objXML.load(server.MapPath("guestbook.xml"))
 
'取得留言本各元素的集合
Set arrNames = objXML.getElementsByTagName("Name")
Set arrEmails = objXML.getElementsByTagName("Email")
Set arrURLS = objXML.getElementsByTagName("Url")
Set arrMessages = objXML.getElementsByTagName("Content")
Set arrTimes = objXML.getElementsByTagName("Time")
 
Response.Write "<table border='0' width='758' bgcolor='#ACB375'>"
Response.Write "<tr><td bgcolor='#ffb442' align='center' height='26'>"
Response.Write "<b>各位的留言如下:</b>"
Response.Write "</td></tr>"
 
'輸出留言本各元素的內容,最新的留言先顯示
For x=arrNames.length-1 To 0 Step -1
Response.Write "<tr><td>姓名:<a href=mailto:" & arrEmails.item(x).text & ">" & arrNames.item(x).text & "</a></td></tr>"
Response.Write "<tr><td>網址:<a href=" & arrURLS.item(x).text & " target='_blank'>" & arrURLS.item(x).text & "</a><td></tr>"
Response.Write "<tr><td>留言內容:</td></tr>"
Response.Write "<tr><td bgcolor='#ccb442'>" & arrMessages.item(x).text & "</td></tr>"
Response.Write "<tr><td bgcolor='#ccb442'>" & arrTimes.item(x).text & "</td></tr>"
Response.Write "<tr><td> </td></tr>"
Next
 
Response.Write "</table>"
Set objXML = nothing
End Function
 
'向XML檔案添加留言記錄的函數addEntry()
Function addEntry()
 
'定義局部變數
Dim strName
Dim strEmail
Dim strURL
Dim strMessage
 
'取得留言表單的輸入內容
strName = Request.Form("Name")
strEmail = Request.Form("Email")
strURL = Request.Form("Url")
strMessage = Request.Form("Content")
strTime = Request.Form("Time")
 
Dim objXML
Dim objEntry
Dim objName
Dim objEmail
Dim objURL
Dim objMessage
Dim objTime
 
'向XML檔案添加留言內容
Set objXML = server.createObject("Msxml2.DOMDocument")
objXML.async = false
objXML.load(server.MapPath("guestbook.xml"))
 
Set objEntry = objXML.createNode("element", "Record", "")
objXML.documentElement.appendChild(objEntry)
 
Set objName = objXML.createNode("element", "Name", "")
objEntry.appendChild(objName)
objName.text = strName
 
Set objEmail = objXML.createNode("element", "Email", "")
objEntry.appendChild(objEmail)
objEmail.text = strEmail
 
Set objURL = objXML.createNode("element", "Url", "")
objEntry.appendChild(objURL)
objURL.text = strURL
 
Set objMessage = objXML.createNode("element", "Content", "")
objEntry.appendChild(objMessage)
objMessage.text = strMessage

Set objTime = objXML.createNode("element", "Time", "")
objEntry.appendChild(objTime)
if strTime="" then
 strTime= Now()
end if
objTime.text = strTime 
 
objXML.save(server.MapPath("guestbook.xml"))
 
Response.Redirect("guestbook.asp")
 
End function
 
'填寫和發送留言表單的函數entryForm()
Function entryForm()
Response.Write "<table width='758' border='0' bgcolor='#ACB375'>"
Response.Write "<tr><td>"
Response.Write "<p align='center'><b>訪客留言(XML版)</b></p>"
Response.Write "<hr size='1' color='#847A39' width='100%' noshade>"
Response.Write "<form action=guestbook.asp?action=addEntry method=post>"
Response.Write "<table border='0' align='center'>"
Response.Write "<tr><td>您的姓名:</td><td><input type=text name='Name' /> *必填</td></tr>"
Response.Write "<tr><td>電子郵件:</td><td><input type=text name='Email' /> *選填</td></tr>"
Response.Write "<tr><td>您的Url:</td><td><input type=text name='Url' /> *選填</td></tr>"
Response.Write "<tr><td> </td><td><input type='hidden'  name='Time' /></td></tr>"
Response.Write "<tr><td>您的留言:<br />*必填</td><td><textarea name='Content' cols=40 rows=5></textarea></td></tr>"
Response.Write "<tr><td> </td><td><input type=submit value='發布留言' />"
Response.Write "   <input type=reset value='取消' /></td></tr>"
Response.Write "</table>"
Response.Write "</form>"
Response.Write "</td></tr>"
Response.Write "</table>"
End Function
%>

<%
'判斷是否發送了留言,並更新留言資訊
Dim a
a = Request.Querystring("action")
If a<>"" Then
addEntry
else
init
End If
%>

 

<!--#include file="htmlfoot.asp"-->

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.