Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generic Form Mailer in asp

Status
Not open for further replies.

andnos

Technical User
Nov 21, 2005
48
US
Thanks for the help I got yesterday, today I'm back. I'm looking for a generic form mailer in asp. Where everything would be set in the HIDDEN fields of the form and passed to the script and the script would read it and email the contents of the script.

I've used one in PHP before:

But I'm working in ASP now. Anybody have any suggesions? or will I have to rewrite the above in ASP.

Thanks in advance,

Andy
 
I guess what I'm looking for the most is help with running through all of the variables that are posted from the form and assigning them variables.
 
ASP will automagically populate the "Request" object with all of the submitted form elements... it basically parses the HTTP Request into a collection. A collection is like a fancy array designed for key/value pairs... so you can get at the value by key instead of by index...

Say your form had an element with a name property of "Foo" ... on the page that processes the form you might see something like this:
[tt]MyFoo = Request.Form("Foo"):[/tt]

The collection object also supports enumeration with the For/Each/Next construct:[tt]
Dim ThisFoo
For Each ThisFoo in Request
Response.Write ThisFoo & " = " & Request(ThisFoo) & "<BR>"
Next
[/tt]
 
what if I don't know the variables? Becuase this will be a user generated forms, they will set the variables and the values for the variables.
 
andnos, I have been working on a javascript function that will take the entire form and process it to be sent as an email. It keeps the form looking just as it did on the original page but strips out inline code, converts Select boxes to Input fields with the selected value shown and sets the readOnly or disabled properties on the fields as needed so that the submitted email version is static.

Basically, you just put a div tag at the start of the area you want to submit and the </div> at the end. Then you call the function at the end of your validation code, it processes the HTML of the page and stores it in a hidden form field. Then on your asp page you just read that form field and you have the entire body of the message.

I think this is along the idea of what you are looking for.
How effective was that PHP script? Did it pick up everything on the page or just the fields?
My intention is to present the email version as close to the original form as possible.

After I get it working the way I like it I will work to make it all server-side code.


Paranoid? ME?? WHO WANTS TO KNOW????
 
The For/Each/Next will allow you to gather the form elements into a string even though you don't know their names.

This example makes a string named sEmailFields that you could append to your email body text to report what was submitted on the form.
[tt]
Dim ThisFoo, sEmailFields
For Each ThisFoo in Request
sEmailFields = sEmailFields & ThisFoo & " = " & Request(ThisFoo) & vbCrLf
Next
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top