Help with JavaScript CDONTS code

C

cmcvicker

I have the following code in an ASP webpage where a member has logged
in and wants to change his company information. This page lists the
fields and records currently in our database (Access) and he is able to
make changes and submit it. My code updates the database fine and
redirects them to another page fine.

Now I want that information emailed to me as well. I have found code
and spent hours tweeking it to work and I finally get NO errors. The
only problem is that when I receive the e-mail, all of the fields say
undefined instead of the actual record. For instance:

THIS IS THE EMAIL:

Company: undefined
Division: undefined
Mailing Address: undefined



THIS IS THE CODE:

<%

var objCDO = Server.CreateObject("CDONTS.NewMail");


objCDO.From = "[email protected]"
objCDO.To = "[email protected]"
objCDO.Subject = "Member Company Updated!"
objCDO.Body = "The following member company information has been
updated." + "\n\n"
+ "Company: " + Request.Form("MbrCompany") + "\n"
+ "Division: " + Request.Form("email") + "\n"
+ "Mailing Address: " + Request.Form("MbrMailingAddress") + "\n"
+ "Mailing City, State, Zip: " + Request.Form("MbrMailingCity") + " "
+ Request.Form("MbrMailingState") + " " + Request.Form("MbrMailingZip")
+ "\n\n"
+ "Shipping Address: " + Request.Form("MbrShippingAddress") + "\n"
+ "Shipping City, State, Zip: " + Request.Form("MbrShippingCity") + "
" + Request.Form("MbrShippingState") + " " +
Request.Form("MbrShippingZip") + "\n\n"
+ "Phone: " + Request.Form("MbrMainPhone") + "\n"
+ "Alt Phone: " + Request.Form("MbrAltPhone") + "\n"
+ "Fax: " + Request.Form("MbrMbrFax") + "\n"
+ "Intl Phone: " + Request.Form("MbrPhoneIntl") + "\n"
+ "Intl Fax: " + Request.Form("MbrFaxIntl") + "\n"
+ "Email: " + Request.Form("MbrEmail") + "\n"
+ "Website: " + Request.Form("MbrWebsite") + "\n\n"
+ "Please file this in the member's folder."
objCDO.BodyFormat = 1
objCDO.MailFormat = 1
objCDO.Send()
objCDO = null

%>

Any help????
 
M

Martin Honnen

I have the following code in an ASP webpage where a member has logged
in and wants to change his company information. This page lists the
fields and records currently in our database (Access) and he is able to
make changes and submit it. My code updates the database fine and
redirects them to another page fine.

Now I want that information emailed to me as well. I have found code
and spent hours tweeking it to work and I finally get NO errors. The
only problem is that when I receive the e-mail, all of the fields say
undefined instead of the actual record. For instance:

THIS IS THE EMAIL:

Company: undefined
objCDO.Body = "The following member company information has been
updated." + "\n\n"
+ "Company: " + Request.Form("MbrCompany") + "\n"

Well if it says undefined then in the ASP page with that code
Request.Form("MbrCompany") yields undefined. As you say that you
redirect then the problem is probably simply that HTTP POST information
is not transferred when redirecting thus any attempt in ASP to read
Request.Form("argname") will give you undefined.
Or that ASP page receives the data in the query string part of the URL
and then
Request.QueryString("MbrCompany")
is the proper way to extract the data.
 
C

ConnieM

Thanks for the response Martin. I tried replacing the Request.Form with
Request.QueryString, but it still gives me undefined values in the
email. Any other suggestions?
 
M

Martin Honnen

ConnieM said:
I tried replacing the Request.Form with
Request.QueryString, but it still gives me undefined values in the
email. Any other suggestions?

For a start don't bother with emailing stuff but find out first how data
is passed to the page, if no data is passed to the page in the query
string then Request.QueryString can't give you any data in the ASP page.
All you are doing is building a string e.g.

"The following member company information has been
updated." + "\n\n"
+ "Company: " + Request.Form("MbrCompany") + "\n"
+ "Division: " + Request.Form("email") + "\n"

or now

"The following member company information has been
updated." + "\n\n"
+ "Company: " + Request.QueryString("MbrCompany") + "\n"
+ "Division: " + Request.QueryString("email") + "\n"

obviously in ASP those Request properties do only reflect what is passed
to the page thus if you get undefined then nothing has been passed to
the page.

So you need to look at how data is passed to the page, to have data in
the query string you for instance would need a link alike
<a href="http://example.com/mail.asp?MbrCompany=company&email=whoever">
the ASP will have values for
Request.QueryString("MbrCompany")
and
Request.QueryString("email")
 
G

Grant Wagner

ConnieM said:
Thanks for the response Martin. I tried replacing the Request.Form
with
Request.QueryString, but it still gives me undefined values in the
email. Any other suggestions?

As Martin has already suggested, you mention that you "redirect to
another page" after processing the form. This will result in "throwing
away" all the values of the Request.QueryString() and Request.Form()
collections.

A redirect simply tells the browser to do a GET on the new URL, anything
in the POST buffer (or originally passed to <FORM
ACTION="yourFormHandler.asp?Something=Whatever">) is lost when the
browser requests the new page.

If you actually want to pass data from the page that handles <FORM
ACTION="..."> to a new page, you have two options:

1) store the values of the form in the Session object and retrieve them
on the new page (I don't recommend this)
2) take the values obtained from Request.Form(), write script to build a
query string containing the information you want and pass it to the
redirect page as part of the redirect.

So, on the page that handles <FORM ACTION="...">

<%
var CompanyNameVar = Request.Form('CompanyName');
var BlahBlahVar = Request.Form('BlahBlah');
var SomethingElseVar = Request.Form('SomethingElse');

// update the database and do whatever

Response.Redirect(
"SendEmail.asp?" +
"CompanyName=" +
Server.URLencode(CompanyNameVar) +
"&BlahBlah=" +
Server.URLencode(BlahBlahVar));
%>

NOW the values of CompanyName, BlahBlah (but NOT SomethingElse) will be
accessible to SendEmail.asp using Request.QueryString(). If you want
SomethingElse too, _you_ have to include it on the query string passed
to SendEmail.asp.

Of course, if you try to pass large (> 512 bytes) of information this
way, you run the risk that the browser won't pass the entire query
string correctly, resulting in lost data.
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top