Nuovamente errori di Guestbook in ASP...
Ho trovato sul web uno script perfetto per il tipo di guest che cercavo, l'unica pecca è che manca l'inserimento del sito nei campi del form...
Ho provato ad aggiungerlo ma evidentemente ho fatto degli erroracci...
Vi allego lo script nel caso qualche anima buona volesse aiutarmi...
Grazie in anticipo, ecco lo script:
<% @language=VBScript %>
<% option explicit %>
<% Response.Buffer = true %>
<%
' ///////////////////////////////////////////////////////////////////////////
' // configuration.
' how many entries are being displayed on one page.
' normally you would specify here something between 20 and 50.
const HITS_PER_PAGE = 5
' string resources, used by other parts of the page.
' used in order to separate code from content.
'-todo: add more.
const IDS_ANONYMOUS = "Anonymous"
const IDS_FIELDSMISSING = "Not all required fields were filled out. Entry was not created."
const IDS_ERRORDELETE = "Error deleting entry."
const IDS_MAIL = "Send e-mail to"
const IDS_ERROR = "Error occured."
' ///////////////////////////////////////////////////////////////////////////
' // global constants/variables.
' there is a global mode for the guestbook.
' depending on that mode, this page behaves different.
' you therefore don't need different pages do to things like
' e.g. inserting or deleting.
' supported modes.
const MODE_NORMAL = 1 ' normal viewing of the guestbook.
const MODE_ERROR = 2 ' an error occured and is displayed.
const MODE_INSERT = 4 ' inserting of a item into the guestbook.
const MODE_DELETE = 8 ' deleting of an item of the guestbook.
const MODE_ADMIN = 16 ' administration-mode: allows deletion of articles.
' read mode. default to normal.
dim mode
mode = Request("mode")
if mode="" then mode = MODE_NORMAL
mode = CLng(mode)
' ///////////////////////////////////////////////////////////////////////////
' // general helper functions.
' minimum and maximum functions.
function min( a, b )
if a<b then min=a else min=b
end function
function max( a, b )
if a>b then max=a else max=b
end function
' formats a date.
function fmtDate( in_str )
fmtDate = FormatDateTime( in_str, 2 )
end function
' replaces '\n' with '
'
function fmtMl( in_str )
if IsNull(in_str) then
fmtMl = ""
exit function
end if
dim str
if in_str<>"" then
str = Replace( in_str, vbCrLf, vbCr )
str = Replace( str , vbLf , vbCr )
str = Replace( str , vbCr , "
" )
fmtMl = str
else
fmtMl = in_str
end if
end function
' allow several html codes, but not all!
function fmtText( byval txt )
' first encode all.
txt = Server.HtmlEncode(txt)
' then decode the allowed tags.
txt = Replace( txt, Server.HtmlEncode("<u>"), "<u>" )
txt = Replace( txt, Server.HtmlEncode("</u>"), "</u>" )
txt = Replace( txt, Server.HtmlEncode(""), "" )
txt = Replace( txt, Server.HtmlEncode(""), "" )
txt = Replace( txt, Server.HtmlEncode(""), "" )
txt = Replace( txt, Server.HtmlEncode(""), "" )
txt = Replace( txt, Server.HtmlEncode(""), "" )
txt = Replace( txt, Server.HtmlEncode(""), "" )
fmtText = fmtMl(txt)
end function
' ///////////////////////////////////////////////////////////////////////////
' // url functions.
' these functions should be used whenever you need a <a href="...">
' tag. instead of specifying an asp page and adding some cryptic
' parameters, you call one of these functions.
' with this approach, you can centralize the url-parameters
' in one place.
' the url of this page.
' automatically adds admin mode if currently active.
function myselfUrl( mode_ )
if (CLng(mode) and CLng(MODE_ADMIN))<>CLng(0) then
mode_ = CLng(mode_) or CLng(MODE_ADMIN)
end if
myselfUrl = Request.ServerVariables("SCRIPT_NAME") & "?mode=" & mode_
end function
' url for viewing the guestbook in normal mode.
function normalUrl
normalUrl = myselfUrl(MODE_NORMAL)
end function
' url for displaying an error.
function errorUrl( error_text )
errorUrl = myselfUrl(MODE_ERROR) & "&error=" & Server.UrlEncode(error_text)
end function
' url for inserting a new entry to the guestbook.
function insertUrl
insertUrl = myselfUrl(MODE_INSERT)
end function
' url for deleting an entry from the guestbook.
function deleteUrl( id )
deleteUrl = myselfUrl(MODE_DELETE) & "&id=" & Server.UrlEncode(id)
end function
function naviUrl( page )
naviUrl = myselfUrl(MODE_NORMAL) & "&pg=" & page
end function
' ///////////////////////////////////////////////////////////////////////////
' // special helper functions.
' creates a connection to the database.
function openDb()
set openDb = Server.CreateObject("ADODB.Connection")
openDb.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source=" &Server.MapPath("guestbook.mdb")
end function
' insert a new entry to the guestbook.
' returns true when successfull, false when failed.
function insertEntry( byref conn )
dim name
dim email
dim text
' read parameters.
name = Request("gb_name")
email = Request("gb_email")
text = Request("gb_text")
' check parameters.
if name="" then name = IDS_ANONYMOUS
if text="" then
insertEntry = false
exit function
end if
' open recordset.
dim rs
set rs = Server.CreateObject("ADODB.Recordset")
rs.Open "Guestbook", conn, 2, 3
' create new recordset.
rs.AddNew
rs("Date") = Now
rs("Name") = name
if email<>"" then rs("EMail") = email else rs("EMail") = null end if
rs("Text") = text
rs.Update
' succeeded.
insertEntry = true
end function
' delete an entry from the guestbook.
' returns true when successfull, false when failed.
function deleteEntry( byref conn )
' read parameters.
dim id
id = Request("id")
' check parameters.
if id="" then
deleteEntry = false
exit function
end if
on error resume next
conn.Execute "DELETE FROM Guestbook WHERE No=" &id
if err<>0 then
deleteEntry = false
else
deleteEntry = true
end if
end function
' check, whether a mode is currently active.
function hasMode( mode_chk )
if (CLng(mode) and CLng(mode_chk))<>0 then
hasMode = true
else
hasMode = false
end if
end function
' ///////////////////////////////////////////////////////////////////////////
' // "main function" and html code.
' open the db.
dim conn
set conn = openDb
' ************************************************** *************************
' new entry.
if hasMode(MODE_INSERT) then
' when a new entry is posted, insert it.
if not insertEntry(conn) then
Response.Redirect errorUrl(IDS_FIELDSMISSING)
else
Response.Redirect normalUrl
end if
end if
' ************************************************** *************************
' delete entry.
if hasMode(MODE_DELETE) then
' when an entry needs to be delete, do it.
if not deleteEntry(conn) then
Response.Redirect errorUrl(IDS_ERRORDELETE& " : " &err.Description)
else
Response.Redirect normalUrl
end if
end if
' ************************************************** *************************
' count the total number of entries.
dim rs
set rs = conn.Execute("SELECT COUNT(*) FROM Guestbook")
dim sum_cnt
sum_cnt = rs(0)
' ************************************************** *************************
' calculate: pages, start, end, etc.
dim cur_page
if Request("pg")="" then
cur_page = 0
else
cur_page = Request("pg")
end if
dim total_pages
total_pages = CLng(CLng(sum_cnt)/CLng(HITS_PER_PAGE))
if (CLng(CLng(sum_cnt) mod CLng(HITS_PER_PAGE))>0) and _
(CLng(sum_cnt)>CLng(HITS_PER_PAGE)) then
total_pages = total_pages+1
end if
if total_pages<=0 then total_pages=1
' the # of the displayed hits.
dim hit_display_start, hit_display_end
hit_display_start = 1+cur_page*HITS_PER_PAGE
hit_display_end = hit_display_start+min(CLng(sum_cnt),CLng(HITS_PER_ PAGE))-1
if hit_display_end>sum_cnt then hit_display_end=sum_cnt
' ---------------------------------
' the numbers must be displayed descending.
dim cntdwn_start
dim cntdwn_end
cntdwn_start = sum_cnt-hit_display_start+1
cntdwn_end = sum_cnt-hit_display_end+1
' ************************************************** *************************
' navigation flags.
' whether there exists a previous or a next page.
dim can_prev_page, can_next_page, can_prevornext_page
if CLng(cur_page)>0 then
can_prev_page=true
else
can_prev_page=false
end if
if CLng(cur_page)<CLng(total_pages)-1 then
can_next_page=true
else
can_next_page=false
end if
can_prevornext_page = can_prev_page or can_next_page
' ---------------------------------
' whether there exists a first and a last page.
dim can_first_page, can_last_page
can_first_page = (can_prevornext_page) and (cur_page>0)
can_last_page = (can_prevornext_page) and (CLng(cur_page)<(CLng(total_pages)-1))
' ************************************************** *************************
' query entries.
set rs = conn.Execute("SELECT * FROM Guestbook ORDER BY Date DESC")
' navigate to start-recordset.
if not (rs.Bof and rs.Eof) then
rs.Move hit_display_start-1
end if
' end of the pure asp-part.
' ///////////////////////////////////////////////////////////////////////////
%>
<% if hasMode(MODE_ERROR) then %>
<font color="#FF0000"><%=IDS_ERROR &" : "& Request("error")%></font>
<% end if %>
<!-- link to insert.
since the insert formular is at the bottom of the page,
the user could not find it. therefore the link at the to. -->
Create new entry</p>
<%=sum_cnt%> Entries found.
Page <%=cur_page+1%> of <%=total_pages%>,
entries <%=cntdwn_start%> to <%=cntdwn_end%>.</p>
<% if can_first_page then %>First page
<%end if%>
<% if can_prev_page then %>Previous page
<%end if%>
<% if can_next_page then %>Next page
<%end if%>
<% if can_last_page then %>Last page
<%end if%></p>
<%
' display discrete pages to jump directly to.
dim i
for i=1 to total_pages
%>
Page <%=i%> 
<%
next
%>
</p>
<%
' ************************************************** *************************
' output all entries.
dim cntdwn
cntdwn = cntdwn_start
dim cnt
cnt = 0
while not rs.Eof and CLng(cnt)<CLng(HITS_PER_PAGE)
cnt = cnt + 1
dim e
if not IsNull(rs("EMail")) then e=true else e=false end if
%>
<hr size="1" color="#C0C0C0">
<%=cntdwn%>.<%if e then%><a title="<%=IDS_MAIL &" "& rs("EMail")%>"
href="mailto:<%=rs("EMail")%>"><%end if%><%=rs("Name")%><%if e then%></a><%end if%>,
<%=fmtDate(rs("Date"))%>
<%if hasMode(MODE_ADMIN) then%>">Delete entry<%end if%>
</p>
<%=fmtText(rs("Text"))%></p>
<%
cntdwn = cntdwn-1
rs.MoveNext
wend
%>
<hr size="1" color="#C0C0C0">
</p>
<a name="insert"></a>Create new entry</p>
Here you can create a new entry to the guestbook.</p>
<form action="<%=insertUrl%>" method="post">
Name:
<input type="text" name="gb_name" size="40">
E-Mail:
<input type="text" name="gb_email" size="40">
Text:
<textarea rows="10" name="gb_text" cols="40"></textarea>
<input type="submit" value="Insert" name="gb_submit">
<input type="hidden" name="insert" value="true">
</form>
</p>
In your text, you can use the followint HTML-tags: <u> <i>
<b> <em> (in lower-case)</p>
<%
%>

Rispondi quotando

