/ Forside / Teknologi / Udvikling / ASP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
ASP
#NavnPoint
smorch 9259
Harlekin 1866
molokyle 1040
Steffanst.. 758
gandalf 657
smilly 564
gibson 560
cumano 530
MouseKeep.. 480
10  Random 410
påkrævede formularfelter...!
Fra : Lars Hørmann


Dato : 01-10-01 19:26

Hej NG!

I en kontakt formular hvor der er enkelte felter som er påkrævet
ønsker jeg:

1.) at man bliver directed til en side hvis man ikke udfylder
formularen forkert - eller hvis man blot submitter uden indhold!

2.) at ekskludere felter som SEND og SLET i afsendelsen.

Herunder er formularen og under den, det ASP script jeg bruger
til at maile med. (ikke noget jeg selv har lavet, men tiltusket
mig!)


på forhånd TAK!

Venligst Lars Hørmann

<form method="post" action="/form2mail.asp" name="Kontakt"
target="_self">


<input type="hidden" name="recipient" value=xx@xx>
<input type="hidden" name="subject" value="Kontakt
&oslash;nskes">
<input type="hidden" name="redirect"
value="kontakt_tak.asp">

<input type="text" name="Navn" size="18">
<input type="text" name="Telefon" size="18">
<input type="text" name="Mail" size="18">

<textarea name="Ang&aring;ende" rows="4"
cols="25"></textarea>

<input type="radio" name="Opringning" value="Ja" checked>
<input type="radio" name="Opringning" value="Nej">
<input type="image" src="/Images/Send.gif" alt="Send"
border="0"
name="SEND" width="50" height="15
a href="#"><img src="/Images/Slet.gif"
onClick="Kontakt.reset();"
width="50" height="15" alt="SLET" border="0">

</form>



<%

' build particulars
method = Request.ServerVariables("HTTP_METHOD")
recipient = Request("recipient")
Subject = Request("Subject")
excludeflds = split(Request("exclude"),",")
fromemail = ""
defemail = ""
   '" &
trim(Replace(Request.ServerVariables("HTTP_HOST"),"www.",""))
redirect = Request("redirect")
mailserver = Request("mailserver")
' set defaults if not specified
If mailserver = "" Then
mailserver = defmailserver
End If
If redirect = "" Then
redirect = "http://" & Request.ServerVariables("HTTP_HOST")
End If
If subject = "" Then
Subject = "Results of form posted from " &
Request.ServerVariables("HTTP_REFERER") & " - " & now()
End If
If recipient = "" Then
recipient = defemail
End If
If fromemail = "" Then
fromemail = defemail
End If
' determine the method of the form (post
' or get)
Select Case lcase(method)
   Case "post"
      'build a delimited list of the field names
      For Each fld In Request.Form
         ' remove the fieldnames of the email configuration fields
         Select Case lcase(fld)
            Case
"exclude","email","subject","recipient","redirect","mailserver"
            ' Do nothing
            Case Else
               tmpfldnames = tmpfldnames & fld & ","
         End Select
      Next
   Case "get"
      'build a delimited list of the field names
      For Each fld In Request.QueryString
         ' remove the fieldnames of the email configuration fields
         Select Case fld
            Case "exclude","email","subject","recipient"
            ' Do nothing
            Case Else
               tmpfldnames = tmpfldnames & fld & ","
         End Select
      Next
End Select
' remove the trailing comma
If mid(tmpfldnames,len(tmpfldnames),1) = "," Then
   tmpfldnames = mid(tmpfldnames,1,len(tmpfldnames)-1)
End If
' build an array of the fieldnames
fldarray = split(tmpfldnames,",")
' build the message header
bodytext = "" & now() & vbcrlf &
"=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-" & vbcrlf
' cycle through all of the fields
For Each fld In fldarray
   PrintFld = True
   ' exclude fields In the exclude list
   For Each checkfld In excludeflds
      If trim(lcase(checkfld)) = trim(lcase(fld)) Then
         PrintFld = False
      End If
   Next
' continue building the mail message wit
' h the form results
If PrintFld = True Then
   bodytext = bodytext & fld & ": " & request(fld) & vbcrlf
End If
next
sentbin = sendmail(fromemail,recipient,subject,bodytext)
'   ""
Select Case sentbin
   Case True
      Response.Redirect(redirect)
   Case False
      Response.write("Der forekom problemer ved afsendelse af
formularen, tryk ""tilbage"" og prøv venligst igen!.")
End Select

   
Function SendMail(From,Rcpt,Subject,Body)
Set objMailer = CreateObject("CDONTS.Newmail")
objMailer.From = From
objMailer.To = Rcpt
objMailer.Subject = Subject
objMailer.Body = Body
objMailer.Send
Set objMailer = Nothing
SendMail = true
End Function
%>

--
Vil du lære at kode HTML, XHTML, CSS, SSI eller ASP ???
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! => http://www.html.dk/tutorials

 
 
Søg
Reklame
Statistik
Spørgsmål : 177557
Tips : 31968
Nyheder : 719565
Indlæg : 6408871
Brugere : 218888

Månedens bedste
Årets bedste
Sidste års bedste