Help with asp website form

R

Ray at

Mike said:
The best way i learn this basic stuff is by knowing the answer (ie seeing a
working script) so I can see
where its wrong and work backwards.

Fair enough. :]


Here:



<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg, sBody

'''sBody wasn't dimmed before. It must be dimmed
'''when using Option Explicit. (Using Option Explicit
'''is a GOOD habit. I suggest you continue using it.)

'''x was not dimmed either.
Dim x
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next

'''You now have a variable that contains the form data separated by line
breaks.

'''Concatenate IP address:
sBody = sBody & Request.ServerVariables("REMOTE_ADDR")

'''Now your body is ready, create your e-mail object

Set iMsg = CreateObject("CDO.Message")
iMsg.To = (e-mail address removed)
iMsg.Subject = "This is the Subject"
iMsg.From = "Me (e-mail address removed)"

'''For the body text, you want to use the variable from above
iMsg.TextBody = sBody

iMsg.Send

'Response.Redirect "/thank_you.htm"
'Response.REdirect is commented out. It's best not to redirect
'until you know everything's working well.
'
'For the sake of seeing what's going on, let's response.write the value
'of that sBody variable.

Response.Write sBody
'Note that vbCrLf is just a line break. Everything will appear
'on one line in the browser, but that's because a Web page would
'need <br> for line breaks. You don't care if it's displayed all
'in one line in the browser. A view-source will show it to you
'the same way that you will (hopefully) see it in an e-mail.
%>


Ray at work
 
M

Mike

Nope, no joy.
i think im going to have to scrap this particular script and try and find
downloadable working script that i can play around with.
Thanks for all your help Ray. I see what youre saying but can't
understand why it doesn't work then assuming everything is correct.


<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg, sBody
Dim x
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next
sBody = sBody & Request.ServerVariables("REMOTE_ADDR")
Set iMsg = CreateObject("CDO.Message")
iMsg.To = "(e-mail address removed)"
iMsg.Subject = "This is the Subject"
iMsg.From = "Me <[email protected]>"
iMsg.TextBody = sBody
iMsg.Send
Response.Redirect "/thank_you.htm"
%>
 
R

Ray at

What's no joy? Did you get an error? COMMENT OUT THE REDIRECT and maybe
you'll see something. What isn't working? There is nothing wrong with the
code below. Perhaps someone else can chime in to verify this.

Ray at work
 
M

Mike

Ray at said:
What's no joy? Did you get an error? COMMENT OUT THE REDIRECT and maybe
you'll see something. What isn't working? There is nothing wrong with the
code below. Perhaps someone else can chime in to verify this.

Ray at work


Just goes to a HTTP 500 error page. Wonder if it could be the host:
www.hostmysite.com
 
R

Ray at

Okay, we're one inch closer now. The next step is to find out what the real
error is. Read this and change your setting and try again. You will see
the error.

www.aspfaq.com/2109

Ray at work
 
M

Mike

Thanks Ray / Curt
Have come across that browser issue before, great to know theres a way to
get the real details back!



Microsoft VBScript runtime error '800a01f4'

Variable is undefined: 'x'

/asp/form.asp, line 5

================================

<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next

Set iMsg = CreateObject("CDO.Message")
iMsg.To = (e-mail address removed)
iMsg.Subject = "This is the Subject"
iMsg.From = "Me <[email protected]>"
iMsg.TextBody = "This is the body of the message"
Request.ServerVariables("REMOTE_ADDR")

iMsg.Send
Response.Redirect "/thank_you.htm"
%>
 
R

Ray at

Does this look familiar to you at all? It's from a few posts back:

'''sBody wasn't dimmed before. It must be dimmed
'''when using Option Explicit. (Using Option Explicit
'''is a GOOD habit. I suggest you continue using it.)

'''x was not dimmed either.

--

Ray at home
Microsoft ASP MVP



In
 
M

Mike

Ray at said:
Does this look familiar to you at all? It's from a few posts back:

'''sBody wasn't dimmed before. It must be dimmed
'''when using Option Explicit. (Using Option Explicit
'''is a GOOD habit. I suggest you continue using it.)

'''x was not dimmed either.

yep id already tried Dim didn't work
 
B

Bob Barrows

Mike said:
yep id already tried Dim didn't work

Dammit.

Please stop saying that! We don't know what "didn't work" means! We're not
looking over your shoulder!

Sorry, but this is frustrating - you have been asked several times in this
thread to explicitly describe your problem without using the words "did not
work".


Show the revised code, and show the error you you get when you run it!

Are you saying that you still get the

Variable is undefined: 'x'

error when you put the line

Dim x

into your code? That's not right, show us the code that produces the error.

Bob Barrows
 
M

Mike

Ouch.
I'm trying lots of variations therefore it would be impossible to
keep posting everything i try.

Example:

Microsoft VBScript compilation error '800a03f2'

Expected identifier

/asp/medical1.asp, line 5

Dim For Each x in request.form
----^

====================================

<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
Dim For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next

Set iMsg = CreateObject("CDO.Message")
iMsg.To = (e-mail address removed)
iMsg.Subject = "This is the Subject"
iMsg.From = "Me (e-mail address removed)"
iMsg.TextBody = "This is the body of the message"
Request.ServerVariables("REMOTE_ADDR")

iMsg.Send
Response.Redirect "/thank_you.htm"
%>
 
B

Bob Barrows

Mike said:
Ouch.
I'm trying lots of variations therefore it would be impossible to
keep posting everything i try.

We can't help you unless you do. Again, we are not looking over your
shoulder.

Look,. we don't expect you to post everything you try. But, we do expect you
to post the information needed to help you with the particular problem you
are posting about. This means: describing your problem without using the
words "did not work", or "it fails", or any variation on this theme. :)
Example:

Microsoft VBScript compilation error '800a03f2'

Expected identifier

/asp/medical1.asp, line 5

Dim For Each x in request.form
----^


See? Now that I see the error and the code, I see the serious mistake you
made :)

"Dim" is used to declare variables, not to put at the beginning of
statements in which the variables are used. This modification will get rid
of that particular error:
<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
Dim x
For Each x in request.form


This will also work:
<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg, x
For Each x in request.form

HTH,
Bob Barrows
 
M

Mike

Thanks for that, i'm with you.
What about the sBody variable?


Microsoft VBScript runtime error '800a01f4'

Variable is undefined: 'sBody'

/asp/test.asp, line 7



<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
Dim x
For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next

Set iMsg = CreateObject("CDO.Message")
iMsg.To = (e-mail address removed)
iMsg.Subject = "This is the Subject"
iMsg.From = "Me <[email protected]>"
iMsg.TextBody = "This is the body of the message"
Request.ServerVariables("REMOTE_ADDR")

iMsg.Send
Response.Redirect "/thank_you.htm"
%>
 
B

Bob Barrows

Mike said:
Thanks for that, i'm with you.
What about the sBody variable?


Microsoft VBScript runtime error '800a01f4'

Variable is undefined: 'sBody'

/asp/test.asp, line 7
Same solution: add a line to declare (define) the variable:

dim sBody

HTH,
Bob Barrows
 
M

Mike

I'd already tried that but the form just submits the text "This is the body
of the message"
rather than the form field data.
Basically im back exactly where i started yesterday but with a little more
knowledge about Dim

Does anyone out there have a 'working script' which submits the contents of
a form???


<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
Dim x
For Each x in request.form
Dim sBody
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next

Set iMsg = CreateObject("CDO.Message")
iMsg.To = (e-mail address removed)
iMsg.Subject = "This is the Subject"
iMsg.From = "Me <[email protected]>"
iMsg.TextBody = "This is the body of the message"
Request.ServerVariables("REMOTE_ADDR")

iMsg.Send
Response.Redirect "/thank_you.htm"
%>
 
A

Alex Goodey

you need this -
iMsg.TextBody = sBody

instead of this -
iMsg.TextBody = "This is the body of the message"
 
R

Ray at

I'm sorry.

Will you go back and READ THIS THREAD AGAIN?! Will you please TRY to
comprehend what other people wrote? I explained why you get "This is the
body of the message" in the e-mail before. Did you read it? Have you read
any of these replies, or are you just skipping right to the code hoping it
works. And when it doesn't work, you take ZERO seconds to try to learn why?
I'm sorry, but if you had been reading the posts with the desire to learn
and figure out what's going on, you have would had this working two days
ago. Every piece of information you could possibly need exists in this
thread. So go back and just keep reading until YOU figure it out. This
will help you learn ASP instead of learning how to copy and paste.

--

Ray at home
Microsoft ASP MVP



In
 
M

Mike

Ray at said:
I'm sorry.

Will you go back and READ THIS THREAD AGAIN?! Will you please TRY to
comprehend what other people wrote? I explained why you get "This is the
body of the message" in the e-mail before. Did you read it? Have you read
any of these replies, or are you just skipping right to the code hoping it
works. And when it doesn't work, you take ZERO seconds to try to learn why?
I'm sorry, but if you had been reading the posts with the desire to learn
and figure out what's going on, you have would had this working two days
ago. Every piece of information you could possibly need exists in this
thread. So go back and just keep reading until YOU figure it out. This
will help you learn ASP instead of learning how to copy and paste.

I was replying to Bob, Piss off you arse hole.
 
M

Mike

Peter Foti said:
Try this:

<%@ Language=VBScript %>
<%
Option Explicit
Dim iMsg
Dim x
Dim sBody

For Each x in request.form
sBody = sBody & x & " = " & request.form(x) & vbCrLf
Next

Set iMsg = CreateObject("CDO.Message")
iMsg.To = (e-mail address removed)
iMsg.Subject = "This is the Subject"
iMsg.From = "Me <[email protected]>"
iMsg.TextBody = sBody & Request.ServerVariables("REMOTE_ADDR")

iMsg.Send
Response.Redirect "/thank_you.htm"
%>


Regards,
Peter Foti



Thanks Peter, You're a good guy.
 
M

Mike

Alex Goodey said:
you need this -
iMsg.TextBody = sBody

instead of this -
iMsg.TextBody = "This is the body of the message"


Thanks for that Alex, much appreciated
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top