Forum Moderators: open

Message Too Old, No Replies

ASP "Request.QueryString"

Help on syntax

         

mossimo

4:55 pm on May 9, 2003 (gmt 0)

10+ Year Member



I know thares a way to do this; I want the "Mailer.FromName" to contain data from two form field inputs. as seen bellow ("FIRST_NAME")or any other named form data works fine but how to you combine two data fields so the email recipient sees as the from line the First & Last name?

Mailer.FromName = Request.QueryString("FIRST_NAME")

I tried this and it did not work ("FIRST_NAME") & ("LAST_NAME")

GaryK

4:59 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're closer to it than you think.

Mailer.FromName = Request.Form("FIRST_NAME") & " " & Request.Form("LAST_NAME")

I think that will work for you.

It's a good idea to filter your form input through a function you can write that will only allow acceptable characters in the form's input to keep hackers at bay and keep your input string clean. I also like to limit the length of each form's input and I do that as a parameter that's passed to the function that scans each form element.

[Edited for clarity.]

[edited by: GaryK at 5:32 pm (utc) on May 9, 2003]

mossimo

5:29 pm on May 9, 2003 (gmt 0)

10+ Year Member



Close really close, I tried that and It created a first and last name only if there is a space and two entrees in the first name input ignoring the last name input. Not to bad I guess I can always combine first and late name into “enter your first and last name” one field.

GaryK

5:38 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unless you have a typo somewhere in the last name field your results don't make sense.

Are there form elements on the page named FIRST_NAME and LAST_NAME? Are you using these same two element names when calling Request.Form?

mossimo

5:52 pm on May 9, 2003 (gmt 0)

10+ Year Member



You are right I had
Request.QueryString("FIRST_NAME") & " " & Request.Form("LAST_NAME")
And not what you said so I tried it and no luck mail send did not even send got an error. The answer to your question is yes I do have “form elements on the page named FIRST_NAME and LAST_NAME”. If it’s any help the full mail script is:

<%
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "smtp.myhost.com"
Mailer.FromName = Request.QueryString("FIRST_NAME") & " " & Request.Form("LAST_NAME")
Mailer.FromAddress = "postmaster@mydomain.com"
Mailer.AddRecipient Request.QueryString("addressto"), Request.QueryString("addressto")
Mailer.Subject = "AutoMail_NEW_SUB!"
Mailer.BodyText = Request.QueryString("txtmsg")
Mailer.BodyText = Request.QueryString("FIRST_NAME")
Mailer.BodyText = Request.QueryString("LAST_NAME")
Mailer.BodyText = Request.QueryString("EMAIL_ADDRESS")
Mailer.BodyText = Request.QueryString("ZIP_CODE")

if not Mailer.SendMail then
Response.Write " Mailing Failed... Error is: <br>"
Response.Write Mailer.Response
else
Response.Write "sent successfully Thank You.<p>"
end if
%>

GaryK

6:13 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In your example you're still using QueryString. I think if you'll replace each occurrance of "QueryString" in your code with "Form" the script will work.

But you still have another problem area. Each time you assign some form input to BodyText you're overwriting what was there before. This would work better:

Mailer.BodyText = _
Request.Form("txtmsg") & vbCrLf & _
Request.Form("FIRST_NAME") & vbCrLf & _
Request.Form("LAST_NAME") & vbCrLf & _
Request.Form("EMAIL_ADDRESS") & vbCrLf & _
Request.Form("ZIP_CODE")

mossimo

6:32 pm on May 9, 2003 (gmt 0)

10+ Year Member



BINGO got it! and the winner is:

Mailer.FromName = Request.QueryString("FIRST_NAME") & " " & Request.QueryString("LAST_NAME")

mossimo

6:55 pm on May 9, 2003 (gmt 0)

10+ Year Member



Thanks GaryK for all your help

GaryK

7:15 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm glad it's working for you. :-)

davegerard

3:29 am on May 23, 2003 (gmt 0)

10+ Year Member



Are these two guys really on the same page?

GaryK

2:42 pm on May 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



He kept referring to the QueryString collection. My preference is to use the Form collection. It doesn't appear to make any difference except perhaps in terms of performance so I didn't see any point in pursuing the QueryString vs. Form issue. Is that what you meant by us not being on the same page?

txbakers

4:50 pm on May 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've given up using QueryString and Form, unless I need something specific from the Query String.

Better to use Request(FIRST_NAME) and let the program decide where it will take it from.