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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hello I have the following code

Status
Not open for further replies.

LaPluma

Programmer
Feb 3, 2002
139
DE
Hello

I have the following code on form.asp which checks that all fields in the form have been completed. The code works.

<%
If Request.Form.Count > 0 Then
Name = Trim(Request.Form(&quot;t1&quot;))
Email = Trim(Request.Form(&quot;t2&quot;))
Message = Request.Form(&quot;S1&quot;)


'data validation
If Name = &quot;&quot; Then
ErrorMsg = ErrorMsg & &quot;Please enter your name<br>&quot;
End If
If Email = &quot;&quot; Then
ErrorMsg = ErrorMsg & &quot;Please enter your email address<br>&quot;
End If
If Message = &quot;&quot; Then
ErrorMsg = ErrorMsg & &quot;Please write your message<br>&quot;
End If


If ErrorMsg = &quot;&quot; Then

'when the name, email and message fields have been checked, redirect the visitor
Response.Redirect &quot;whatever.asp&quot;
End If
End If
%>

<form action=&quot;<%= Request.ServerVariables(&quot;SCRIPT_NAME&quot;) %>&quot; method=post>

<% If ErrorMsg <> &quot;&quot; Then %>
<p><font color=&quot;#FFFFFF&quot;><b><%= ErrorMsg %></b></font><p>

<% End If %>


<input type=text name=&quot;t1&quot; value=&quot;<%= t1 %>&quot;>
<input type=text name=&quot;t2&quot; value=&quot;<%= t2 %>&quot;>
<textarea name=&quot;S1&quot; cols=&quot;20&quot; rows=&quot;3&quot; value=&quot;<%= S1 %>&quot;></textarea></font>

Any error messages appear on the same page (form.asp). When all fields have been completed correctly, the page redirects to whatever.asp:

Response.Redirect &quot;whatever.asp&quot;

Using the same variables as above (namely &quot;t1&quot;), I would now like to thank &quot;t1&quot; (name) for submiting the form. The thank you message should appear on whatever.asp.

Can anybody on the forum, please indicate how I might do that? That is, how can I combine the two functions?

Many thanks

LaPluma
 
i would store t1 in a session var:
session(&quot;t1&quot;) = request.form(&quot;t1&quot;)

then on whatever.asp:
Thank you, <%= session(&quot;t1&quot;) %>


it could also be done by sending t1 through the querystring, but that's not so elegant.

=========================================================
if (!succeed) try();
-jeff
 
Hello jemminger

That has worked wonders! Thank you.

I don't really understand the logic behind it, so I will study the code. Still, it works! Great!

Best wishes

LaPluma
 
Hello jemminger

Many thanks again for your reply.

Yes, I have inserted the following into the form page:

session(&quot;t1&quot;) = request.form(&quot;t1&quot;)

and

<p>Thank you <%= session(&quot;t1&quot;) %></p>

in the whatever.asp page.

It works fine, but I have some script (CDONTS) which sends a copy of the form to the Webmaster and a copy to the person who completed the form, and that script doesn't work anymore. (No e.mail messages are sent out to anyone).

This is the full CDONTS code:

<%
Dim t1name,t1,t2name,t2
t1name = &quot;name&quot;
t1 = Request.Form(&quot;t1&quot;)
t2name = &quot;email&quot;
t2 = Request.Form(&quot;t2&quot;)
Dim stname,st
stname = &quot;comments&quot;
st = Request.Form(&quot;s1&quot;)
Dim ObjMail
Set ObjMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)
ObjMail.To = &quot;whoever@aol.com&quot;
ObjMail.CC = t2
ObjMail.From = t2
ObjMail.Subject = &quot;Feedback&quot;
ObjMail.Body = t1name & vbcrlf&_
t1 & vbcrlf&_
t2name & vbcrlf&_
t2 & vbcrlf&_
stname & vbcrlf&_
st
ObjMail.Send
Set ObjMail = Nothing
%>

Do you know what I might be doing wrong?

LaPluma

 
the session variable code that you added is unrelated and should have no effect on the email code.

what page is this cdonts code on?

check your badmail folder in the mailroot directory on the webserver...if there's anything in it, you can typically open some of the files in a text editor and read the reason why the mail failed.

right now your script is set up to send the email to &quot;whoever@aol.com&quot;, plus Cc: to whatever is entered for &quot;t2&quot;. if this email address is invalid, it could cause the mail to fail. =========================================================
if (!succeed) try();
-jeff
 
Hello jemminger

Thanks again for your message.

The e.mail address I use is a valid one (my own real one)- as is the email ddress referred to in t2.

The CDONTS page is actually on the page which I called whatever.asp.

I have contacted the web hosting service which the site resides on and asked them about going throught the badmail files.

Here is the full (relevant) code on the page which holds the form:

<%
If Request.Form.Count > 0 Then
Name = Trim(Request.Form(&quot;t1&quot;))
Email = Trim(Request.Form(&quot;t2&quot;))
Message = Request.Form(&quot;S1&quot;)

session(&quot;t1&quot;) = request.form(&quot;t1&quot;)


'data validation
If Name = &quot;&quot; Then
ErrorMsg = ErrorMsg & &quot;Please enter your name<br>&quot;
End If
If Email = &quot;&quot; Then
ErrorMsg = ErrorMsg & &quot;Please enter your email address<br>&quot;
End If
If Message = &quot;&quot; Then
ErrorMsg = ErrorMsg & &quot;Please write your message<br>&quot;
End If


If ErrorMsg = &quot;&quot; Then
'use this to perform any database validations

'when the name, email and message fields have been checked, redirect the visitor
Response.Redirect &quot;welcome1.asp&quot;
End If
End If
%>

<form action=&quot;<%= Request.ServerVariables(&quot;SCRIPT_NAME&quot;) %>&quot; method=post>

<% If ErrorMsg <> &quot;&quot; Then %>
<p><font color=&quot;#FFFFFF&quot;><b><%= ErrorMsg %></b></font><p>

<% End If %>

<input type=text name=&quot;t1&quot; value=&quot;<%= t1 %>&quot;>

<input type=text name=&quot;t2&quot; value=&quot;<%= t2 %>&quot;>

<textarea name=&quot;S1&quot; <%= S1 %>&quot;></textarea>

And here is the code from the whatever.asp page:

<%
Dim t1name,t1,t2name,t2
t1name = &quot;name&quot;
t1 = Request.Form(&quot;t1&quot;)
t2name = &quot;email&quot;
t2 = Request.Form(&quot;t2&quot;)
Dim stname,st
stname = &quot;comments&quot;
st = Request.Form(&quot;s1&quot;)
Dim ObjMail
Set ObjMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)
ObjMail.To = &quot;whoever@aol.com&quot;
ObjMail.CC = t2
ObjMail.From = t2
ObjMail.Subject = &quot;Feedback&quot;
ObjMail.Body = t1name & vbcrlf&_
t1 & vbcrlf&_
t2name & vbcrlf&_
t2 & vbcrlf&_
stname & vbcrlf&_
st
ObjMail.Send
Set ObjMail = Nothing
%>

<p>Thank you <%= session(&quot;t1&quot;) %></p>


As I think I have mentioned before, the page does personalise the 'Thank you' and error messages on the form are shown when they are made, but the CDONTS e.mail function doesn't seem to work.

On the other hand, this form (let's call it form2.asp) DOES have a CDONTS function which works (it sends emails and personalises the 'Thank you' page - but doesn't highlight form errors which is something I want):

<input type=&quot;text&quot; name=&quot;t1&quot; size=&quot;15&quot;>

<input type=&quot;text&quot; name=&quot;t2&quot; size=15>

<textarea name=&quot;S1&quot;></textarea>

And this is, let's say, whatever2.asp:

<%
Dim t1name,t1,t2name,t2
t1name = &quot;name&quot;
t1 = Request.Form(&quot;t1&quot;)
t2name = &quot;email&quot;
t2 = Request.Form(&quot;t2&quot;)
Dim stname,st
stname = &quot;comments&quot;
st = Request.Form(&quot;s1&quot;)
Dim ObjMail
Set ObjMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)
ObjMail.To = &quot;whoever@aol.com&quot;
ObjMail.CC = t2
ObjMail.From = t2
ObjMail.Subject = &quot;Feedback&quot;
ObjMail.Body = t1name & vbcrlf&_
t1 & vbcrlf&_
t2name & vbcrlf&_
t2 & vbcrlf&_
stname & vbcrlf&_
st
ObjMail.Send
Set ObjMail = Nothing
%>

<p>Thank you <%=t1%></p>

I hope this helps you to help me!

Thanks again for your time.

LaPluma
 
realize that the Form collection only exists during the creation of the target page (the submitting form's action)

which means:
if page1.asp has a form that submits to page2.asp, then page2.asp redirects to page3.asp, you can only access page1's form values on page2. they no longer exist on page3.

is this what's happening with your first email script?

=========================================================
if (!succeed) try();
-jeff
 
Hello jemminger

No.

.asp1 (which holds the form) and .asp2 (which thanks the visitor) validates the form fields and personalises the 'Thank you' page. This is what you helped me with earlier with your:

session(&quot;t1&quot;) = request.form(&quot;t1&quot;) on .asp1

and:

<%= session(&quot;t1&quot;) %>

on .asp2.

This works! I am happy with it. But something is wrong with it, in that it doesn't send emails to the Webmaster or the visitor.
________________________________

I also have a .asp3 page and .asp4 page. Not at all related to the above two asp pages. They have nothing to do with one another.

However, .asp3 and .asp4, send emails to the Webmaster and visitor and they, too, work. The .asp3 contains the form, and .asp4 is the 'Thank you' page. This 'Thank you' page works in that it personalises the name of the visitor. They do not, however, check the form fields.

_________________________

So, I have two (shall I call them) programmes. asp1 and asp2 check the form fields and thanks the visitor - but don't send out emails (to the Webmaster and visitor), while asp3 and asp4 do send out emails (to the Webmaster and visitor) and do thank the visitor, but don't check the form fields.

In anideal world, I would like a script which combines these, so that the code checks the fields on the form, emails the Webmaster and visitor, and thanks the visitor for completing the form.

Hope this is clearer - and my apologies for any confusion.

I feel the problem lies somewhere with the t1/&quot;t1&quot;/t2/&quot;t2&quot; etc variables.

Thanks again

LaPluma

 
did you try removing

session(&quot;t1&quot;) = request.form(&quot;t1&quot;) on .asp1
and:
<%= session(&quot;t1&quot;) %>

to see if it starts working again? =========================================================
if (!succeed) try();
-jeff
 
Hello jemminger

I have removed the:

session(&quot;t1&quot;) = request.form(&quot;t1&quot;) on .asp1

and:

<%= session(&quot;t1&quot;) %>

on .asp2.

The form fields are validated - if a field is omitted the code picks up on it - but the 'Thank you' page is not personalised and the emails are NOT sent out.

*********

But this code

<input type=&quot;text&quot; name=&quot;t1&quot; size=&quot;15&quot;>
<input type=&quot;text&quot; name=&quot;t2&quot; size=15>
<textarea name=&quot;S1&quot;></textarea>

on aspX (form)

and this on aspY ('Thank you page which also holds the CDONTS script):

<%
Dim t1name,t1,t2name,t2
t1name = &quot;name&quot;
t1 = Request.Form(&quot;t1&quot;)
t2name = &quot;email&quot;
t2 = Request.Form(&quot;t2&quot;)
Dim stname,st
stname = &quot;comments&quot;
st = Request.Form(&quot;s1&quot;)
Dim ObjMail
Set ObjMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)
ObjMail.To = &quot;SwingJava1@aol.com&quot;
ObjMail.CC = t2
ObjMail.From = t2
ObjMail.Subject = &quot;Feedback&quot;
ObjMail.Body = t1name & vbcrlf&_
t1 & vbcrlf&_
t2name & vbcrlf&_
t2 & vbcrlf&_
stname & vbcrlf&_
st
ObjMail.Send
Set ObjMail = Nothing
%>

<p>Thank you <%=t1%></p>

DOES send out the emails and DOES personalise the 'Thank you' page. But it doesnn't check the form fields.

Neither aspX nor aspY contain your

session(&quot;t1&quot;) = request.form(&quot;t1&quot;) or

<%= session(&quot;t1&quot;) %>

It's all very confusing, isn't it?!

Cheers!

LaPluma





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top