Toon posts:

[ASP] Hoe volgorde mailformulier e-mail aanpassen?

Pagina: 1
Acties:

Verwijderd

Topicstarter
Op de volgende site heb ik een mailformulier gemaakt:
www.giuliohairstyling.nl/formulier.htm

m.b.v. het volgende script wordt de mail verstuurd:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<html>

<%
on error resume next
Set Mailer = Server.CreateObject("CDONTS.NewMail")

if request("van") = "" then
  MailFrom = "bigbob@quicknet.nl"
else
  MailFrom = request("van")
end if

if request("aan") = "" then
  Mailto = MailFrom
else
  MailTo = request("aan")
end if

if request("onderwerp") = "" then
  Subject = "Reactie via uw website"
else
  Subject = request("onderwerp")
end if

Mailer.From = MailFrom
Mailer.To = MailTo
Mailer.Subject = Subject

for each whatever in request.querystring
  Message = Message & whatever & "=" & vbcrlf
  Message = Message & request.querystring(whatever) & vbcrlf & vbcrlf
next

for each whatever in request.form
  Message = Message & whatever & "=" & vbcrlf
  Message = Message & request.form(whatever) & vbcrlf & vbcrlf
next

Mailer.Body = Message
Mailer.Send
Set Mailer = nothing

response.redirect "bedankt.htm"
%>
 
<head>
<title>Mail ASP</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
</body>
</html>

Maar in de e-mail met resultaten die ik krijg staan de ingevoerde velden niet in de volgorde als in het html formulier. Weet iemand hoe ik die volgorde kan aanpassen ? Ook heb ik in het mailformulier een veld gemaakt om een file mee te sturen (cv) maar in de e-mail die ik krijg is alleen de directorynaam vermeld (de file wordt niet als attachment mee verstuurd). Hoe pas ik dit aan ?

  • mbravenboer
  • Registratie: Januari 2000
  • Laatst online: 06-11-2025
Ik heb je code even tussen [ code] ... [ /code] gezet. Het komt dan een stukje beter over :) .

Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment


  • Basszje
  • Registratie: Augustus 2000
  • Laatst online: 15-09 11:04

Basszje

Reisvaap!]

Cv als attachment heb je toch een methode voor :?

Volgens mij moet je dan in je <form> een <input type="file"> meegeven. :?

En wat bedoel je precies met goede methode ?

Beware of listening to the imposter; you are undone if you once forget that the fruits of the earth belong to us all, and the earth itself to nobody.


Verwijderd

Topicstarter
Goede volgorde bedoel je toch ?

Daarmee bedoel ik dat als ik in mijn html formulier bijv eerst om zijn naam en dan om zijn adres vraag dat in de e-mail eerst zijn adres staat en dan zijn naam. Hij gooit dus alles door elkaar.

En in de source van http://www.giuliohairstyling.nl/formulier.htm
staat type = file bij het opvragen van het cv maar ik krijg alleen de directorynaam in de e-mail en dus niet als attachment.

  • Nazgul
  • Registratie: Februari 2000
  • Laatst online: 11-10-2022

Nazgul

Digital Pizza Crew

Heb ooit op Inet iets gevonden daarover. Weet alleen niet meer waar.

Maar hier het relevante stukje uit mijn 'archief' gecopied en gepasted:
Question: How can I retrieve the fields in my form in the order they appear in the form?

Answer: If you simply do
code:
1
2
3
4
5
<%
For Each Item In Request.Form
    Response.Write Item & ": " & Request.Form(Item) & "<BR>" & vbNewLine
Next
%>

you usually will not see the form fields appear in the order in which you placed them on the form. (If they do appear in order, either the form was very small or you got very lucky.)

The only reliable way to retrieve the form fields in order works like this:
code:
1
2
3
4
5
6
7
<%
For ix = 1 to Request.Form.Count
    fieldName = Request.Form.Key(ix)
    fieldValue = Request.Form.Item(ix) 
    ...
Next
%>


This seems to work up to a certain point (at least 64 form fields, though I have heard reports of up to 256 form fields), at which point even it can break down.

If all you want is a solution, you can quit reading now. If you want to know why this happens, read on...

When you do Request.Form you are accessing a VBScript collection. And a "collection" is
actually essentially the same thing as a "Scripting.Dictionary". That is, it is a hash table keyed by the names of the items in the Form.

So when you do For each item in Request.Form
you are asking VBScript to traverse the KEYS of the collection, which means you will get the items in whatever order the hashing algorithm stored them in.

So the only way to predict the order is to know what hashing algorithm MS uses for the given collection. But even knowing that would only allow prediction of the order, not specifying the order.

Why does the method shown above work? Because underneath it all, the collection is really sitting on top of a "dynamic array." And when you use the code shown, you are bypassing the upper levels of the collection code and delving down to that array. And you are seeing the items in array order, which just happens to also be form field order. Even this ordering breaks down when the collection needs to "re-hash" the keys, which is why there is an upper limit (sorry I don't know for sure what it is) to the number of form fields that can be retrieved in order via the above code.

No trees were killed in the sending of this message. However a large number of electrons were terribly inconvenienced.


Verwijderd

Topicstarter
Sorry...maar als ik de bovenstaande code kopieer naar mijn asp file dan gaat het nog niet goed. Iemand anders nog een goed idee ?

Verwijderd

Topicstarter
zo dus (handmatig volgorde maken !!!):
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<%
on error resume next
Set Mailer = Server.CreateObject("CDONTS.NewMail")

if request("van") = "" then
  MailFrom = "bigbob@quicknet.nl"
else
  MailFrom = request("van")
end if

if request("aan") = "" then
  Mailto = MailFrom
else
  MailTo = request("aan")
end if

if request("onderwerp") = "" then
  Subject = "Reactie via uw website"
else
  Subject = request("onderwerp")
end if

Mailer.From = MailFrom
Mailer.To = MailTo
Mailer.Subject = Subject

   Message = Message & request.form("naam") & vbcrlf & vbcrlf
   Message = Message & request.form("manvrouw") & vbcrlf & vbcrlf
   Message = Message & request.form("van") & vbcrlf & vbcrlf
   Message = Message & request.form("adres") & vbcrlf & vbcrlf
   Message = Message & request.form("postcode") & vbcrlf & vbcrlf
   Message = Message & request.form("woonplaats") & vbcrlf & vbcrlf
   Message = Message & request.form("telefoon") & vbcrlf & vbcrlf
   Message = Message & request.form("commentaar") & vbcrlf & vbcrlf
   Message = Message & request.form("cv") & vbcrlf & vbcrlf
   Message = Message & request.form("schoonmaak") & vbcrlf & vbcrlf
   Message = Message & request.form("administratief") & vbcrlf & vbcrlf
   Message = Message & request.form("bouw") & vbcrlf & vbcrlf
   Message = Message & request.form("techniek") & vbcrlf & vbcrlf
   Message = Message & request.form("bron") & vbcrlf & vbcrlf
   
Mailer.Body = Message
Mailer.Send
Set Mailer = nothing

response.redirect "bedankt.htm"
%>
Pagina: 1