If NAME & MAIL & TITLE & MSG = "" Then Call Disp ElseIf NAME="" Or TITLE = "" Or MSG = "" Then Response.Write "<BR><FONT SIZE=6 COLOR=#FF0000>E-Mail 以外の項目は全て入力して下さい。</FONT><BR><BR>" Else Call Write Call Disp End If %>
<BLOCKQUOTE> <% ' **** スクリプト部分 **** ' 入力フォーム内容の取得 name = Request.Form("name") office = Request.Form("office") mail = Request.Form("mail") title = Request.Form("title") body = Request.Form("body") address = Request.ServerVariables("REMOTE_ADDR") ' テキストファイルを扱うオブジェクトを生成 Set FS = Server.CreateObject("Scripting.FileSystemObject") ' ログファイルの場所を指定 logfile = Server.MapPath("bbslog.txt")
' フォームへの入力がない場合はログファイルの読み込みだけ If Request.Form="" Then Set inTS = FS.OpenTextFile(logfile, 1, False) buf = inTS.ReadAll Set inTS = Nothing Response.Write buf
' 入力に不備がある場合の表示 ElseIf name="" Or office="" Or title="" Or body="" Then Response.Write "<HR><P ALIGN=center><FONT SIZE=5 COLOR=#ff0000>" & _ "<B>'E-Mail'以外の項目は全て入力して下さい。</B></FONT></P>"
' 正常に入力された場合のログファイルへの書き込み処理 Else ' タグとして認識しないようにする処理 name = Replace(name, "<", "<") : name = Replace(name, ">", ">") office = Replace(office, "<", "<") : office = Replace(office, ">", ">") mail = Replace(mail, "<", "<") : mail = Replace(mail, ">", ">") title = Replace(title, "<", "<") : title = Replace(title, ">", ">") ' 本文中の改行をタグで書き替える処理 body = Replace(body, Chr(13), "<BR>") : body = Replace(body, Chr(10), "") ' 表示フォーマットに合わせて入力データを加工 ' (タイトル、名前[メールへリンク]、所属、接続先、日時、本文) Wbuf = "<HR><FONT SIZE=4 COLOR=#0088FF><B>" & title & "</B></FONT>" If mail = "" Then Wbuf = Wbuf & " 名前:<B>" & name & "</B>" Else Wbuf = Wbuf & " 名前:<B><A HREF='mailto:" & mail & "'>" & name & "</A></B>" End If Wbuf = Wbuf & " 所属:<B>" & office & "</B> 接続先:" & address & " " & Now Wbuf = Wbuf & "<P>" & body & "<P>" & vbCrLf ' ファイルの読み込みを行うオブジェクトを生成 Set inTS = FS.OpenTextFile(logfile, 1, False) For i = 2 To 30 '表示するログは30件以内 If inTS.AtEndOfLine Then Exit For Wbuf = Wbuf & inTS.ReadLine & vbCrLf Next Set inTS = Nothing ' ファイルへ書き込みを行うオブジェクトを生成 Set outTS = FS.CreateTextFile(LogFile, True) outTS.WriteLine Wbuf 'ファイルへの書き込み処理 Set outTS = Nothing Response.Write "<HR><P ALIGN=center><FONT SIZE=5 COLOR=#ff0000>" & _ "<B>ファイルへの書き込み処理が完了しました。</B></FONT></P>" End If %> </BLOCKQUOTE> <HR> </BODY> </HTML>
分類:[ASP.NET]
asp掲示板を作成したいのですが、うまくできません。
ソースは、aspソースを公開しているHPから
コピーさせてもらったものなんですが…
どこかおかしいのでしょうか。
教えてください。
<%
Set objFile = Server.CreateObject("Scripting.FileSystemObject")
LogFile = Server.MapPath("bbslog.txt")
FormFile = Server.MapPath("form.htm")
NAME = Request.Form("name")
MAIL = Request.Form("mail")
TITLE = Request.Form("title")
MSG = Request.Form("msg")
NAME = Replace(NAME, """", """)
NAME = Replace(NAME, "'", "''")
NAME = Replace(NAME, "|", "|")
NAME = Replace(NAME, "<", "<")
MAIL = Replace(MAIL, """", """)
MAIL = Replace(MAIL, "'", "''")
MAIL = Replace(MAIL, "|", "|")
MAIL = Replace(MAIL, "<", "<")
TITLE = Replace(TITLE, """", """)
TITLE = Replace(TITLE, "'", "''")
TITLE = Replace(TITLE, "|", "|")
TITLE = Replace(TITLE, "<", "<")
MSG = Replace(MSG, """", """)
MSG = Replace(MSG, "'", "''")
MSG = Replace(MSG, "|", "|")
MSG = Replace(MSG, "<", "<")
If NAME & MAIL & TITLE & MSG = "" Then
Call Disp
ElseIf NAME="" Or TITLE = "" Or MSG = "" Then
Response.Write "<BR><FONT SIZE=6 COLOR=#FF0000>E-Mail 以外の項目は全て入力して下さい。</FONT><BR><BR>"
Else
Call Write
Call Disp
End If
%>
<A HREF="viewcode.asp?source=form.htm&disp=no"><FONT SIZE=2>form.htm の表示</FONT></A>
</BODY>
</HTML>
<SCRIPT LANGUAGE=VBScript RUNAT=Server>
Sub Write
MSG = Replace(MSG, Chr(13), "<BR>")
MSG = Replace(MSG, Chr(10), "")
EDate = FormatDateTime(now(), vbShortDate) & " " & FormatDateTime(now(), vbShortTime)
Set InStream = objFile.OpenTextFile(LogFile, 1, False)
sOldLog = InStream.ReadAll
iNo = InStream.line
InStream.Close
sWriteBuf = "<TABLE CELLPADDING=4 WIDTH=100% BORDER><TR>"
sWriteBuf = sWriteBuf & "<TD BGCOLOR=#CCFFCC WIDTH=60>#" & Right("0000" & CSTR(iNo), 4) & "</TD>"
If MAIL = "" Then
sWriteBuf = sWriteBuf & "<TD BGCOLOR=#CCFFCC>" & NAME & "</TD>"
Else
sWriteBuf = sWriteBuf & "<TD BGCOLOR=#CCFFCC><A HREF=" & Chr(34) & "mailto:" & MAIL & Chr(34) & ">" & NAME & "</A></TD>"
End If
sWriteBuf = sWriteBuf & "<TD BGCOLOR=#CCFFCC WIDTH=120 ALIGN=CENTER><FONT SIZE=2>" & EDate & "</FONT></TD></TR></TABLE>"
sWriteBuf = sWriteBuf & "<TABLE CELLPADDING=4 WIDTH=100% BORDER>"
sWriteBuf = sWriteBuf & "<TR><TD BGCOLOR=#CCCCCC COLSPAN=3>" & TITLE & "</TD></TR>"
sWriteBuf = sWriteBuf & "<TR><TD BGCOLOR=WHITE COLSPAN=3>" & MSG & "</TD></TR>"
sWriteBuf = sWriteBuf & "</TABLE><BR>"
Set OutStream = objFile.CreateTextFile(LogFile, True)
OutStream.WriteLine sWriteBuf
OutStream.Write sOldLog
End Sub
Sub Disp
Set InStream = objFile.OpenTextFile(FormFile, 1, False)
buf = InStream.ReadAll
Response.Write buf
InStream.Close
Set InStream = objFile.OpenTextFile(LogFile, 1, False)
buf = InStream.ReadAll
Response.Write "<HR>全部で" & InStream.line - 1 & "件のメッセージが登録されています。<HR>"
Response.Write buf & "<HR>"
InStream.Close
End Sub
</SCRIPT>