View Full Version : How to write out thanks screen?
gorilla1
11-04-2002, 12:38 PM
Let's say I process a subscriber form and then I want to show a blank screen with the message, "thank you for subscribing, hit the back button to return..." or whatever. Is this done by linking to another script with response.redirect?
G
dominicall
11-04-2002, 03:59 PM
Depends what you want to do when you go back..
If all you want to do is go back to the previous page the just...
<a href="javascript:history.back()">
If you want to go back more than one page
<a href="javascript:history.go(-x)">
...where -x is the number of pages you want to go back.
BTW - in both the above examples CF is putting a space in javascript where none should exist...
If you need to process a querystring on the page you go back to then...
<a href="destinationpage.asp?action=youraction">
Hope this helps.
Dominic :D
gorilla1
11-04-2002, 04:34 PM
Thanks Dominic. However, my concern is with getting to the thank you page, on a new screen from the current page, not with going back. Though in going back, if any of the form was entered invalid, I want to be able to retain the values and data that were input, so the viewer does not have to re-enter them.. That s another chalenge.
Ted
dominicall
11-04-2002, 05:38 PM
OK - go have a look at my response in the login screen thread holty was asking about earlier... the solution is essentially the same...
Step 1 - create the form page - default.asp
I'll leave out all the non relevant stuff
<form name="signup" method="post" action="signup.asp">
Username: <input type="text" name="uname">
Password: <input type="text" name="pword">
<input type="submit" value=" Submit ">
<%
If Request.QueryString("error") = "missing" Then
Response.Write "<p><strong>Either the username or password were missing - please try again</strong></p>"
End If
%>
When the user clicks the submit button they'll go to signup.asp which will process the script. You should use a javascript check to ensure that they've completed both text boxes.
Step 2 - Process the script - signup.asp
<%
'get the form data and stuff it into variables
Dim uname, pword
uname = Request.Form("uname")
pword = Request.Form("pword")
'check the username or password aren't blank
If ((uname="" OR IsNull(uname)) OR (pword="" OR IsNull(pword))) Then
Response.Redirect "default.asp?error=missing"
End If
'we've got here so add the data
Dim cmdAddUser
Set cmdAddUser= Server.CreateObject.Command
cmdAddUser.ActiveConnection = your connection string here
cmdAddUser.CommandText = "INSERT INTO tbl_Users (username,password) VALUES (" & uname & "," & pword & ");"
cmdAddUser.CommandType = adCmdText
cmdAddUser.Execute
Set cmdAddUser = Nothing
%>
<!-- Now give a link back to the home page -->
<p>Thanks for signing up - <a href="default.asp">click here</a> to go back to the home page.</p>
Note: technically you don't have to use End If for single check If statements, but I tend to be a bit too correct with my coding - it never hurts.
If I understand correctly, that's what you're trying to do.
Dominic :D
whammy
11-04-2002, 11:28 PM
I usually post everything to the same page, and then depending on my validation, display different HTML with subroutines.
Once you're familiar with doing that, it's much easier than creating 2 or 3 pages... especially if you have a lot of variables to work with.
Here is a very basic example:
http://www.solidscripts.com/email.txt
working at:
http://www.solidscripts.com/email.asp
...although for larger applications I usually break things up even further into smaller subroutines, since if the program has to be changed, it's easier to deal with (just move around your references to the subs, and maybe a couple of tweaks, if you're lucky).
Also note the use of Server.HTMLEncode - that's the right way to use it. I often see people using functions that replace & with & or " with " (hint to Dominicall ;)), when this is unnecessary because Server.HTMLEncode does it for you.
You only want to do this when displaying values in HTML, though! That way you don't mess up your data.
:)
gorilla1
11-05-2002, 03:09 AM
Thanks Dominic and Whammy - that helps.
G
whammy
11-07-2002, 01:48 AM
:cool:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.