Link to home
Start Free TrialLog in
Avatar of docmeat
docmeat

asked on

How to Refresh original dynamic page after submit?

Hello, I have a template page that pulls data off a database of recipes.  A sample url of these pages would look something like:

http://www.gzzzzz.com/zzz-recipe-view.asp?cat=1&id=3882

On this template is a form for people to log in.  

The login submits to another page that has a place to redirect the user:

myGoToUrl = "index.asp"

My question, is there a way to keep the user on the same dynamically generated page, instead of redirecting to some other generic page?
Thank you for any advice!
Avatar of HuyBD
HuyBD
Flag of Viet Nam image

you can get the current url before redirect then pass to new page, after check you can redirect back to original page
<%
dim url
url=Request.ServerVariables("URL")
response.redirect "index.asp?url="&url
%>

Open in new window

Avatar of davemchale
davemchale

easier method... do a response.redirect to request.servervariables("HTTP_REFERER") on the processing page. then you don't need to pass anything extra in the original form post.
Avatar of docmeat

ASKER

davemchale,

I put:

Response.Redirect(request.servervariables("HTTP_REFERER"))

and the page refreshes back properly but loses all the dynamic content, is my syntax wrong?
Thanks for the help!
For reference on the ServerVariables collection: http://www.w3schools.com/asp/coll_servervariables.asp

My apologies... in order to post back with the querystring data (if that's all that's creating the dynamic page, assuming you don't also have form variables that you use to pull content from a database) you should update the response.redirect to the attached code snippet... that will get your QS variables back onto the script path, and if the referer DIDNT have any QS variables then the "worst" you'll see is an extra question mark on the end of the script name which won't hurt anything. You could also do checks to see if the querystring has any content before adding to the string but in this case the one-liner should do you just fine.



response.redirect request.servervariables("HTTP_REFERER") & "?" & request.servervariables("QUERY_STRING") 

Open in new window

Sorry... after posting I re-read your latest post and discovered I misunderstood your comment.

Can you post what your original script URL is, what page you are posting to, and then what URL you are being passed to on the response.redirect? (or get a response.write of the REFERER servervariable and then response.end before doing a redirect).

the HTTP_REFERER variable contains the entire path to the refering script, querystring variables and all. So assuming that those vars are what create your dynamic content, the original post I made SHOULD work for you. Do you have form fields that you pass to the database on your original page that we're losing when you do the next form post?
Avatar of docmeat

ASKER

davemchale, the login script is at:

http://glutenfreeda.com/recipe-login-script.asp

should I attach it instead of a URL?

the posting page is a template that has a URL like this:

http://www.gzzzzz.com/zzz-recipe-view.asp?cat=1&id=3882

pulls from a db.
Hopefully that's what you needed?
Thanks again!

yes please paste the code or attach the file. I'd need to see your ASP code which I can't do over the web by looking at the page :)

does the recpie-view script only use the cat and id variables to pull from the db or are there more variables involved? if you could post source from that it could be helpful as well
Avatar of docmeat

ASKER

see if this helps, sir!
Function Encrypt(strText)
Const strPwd = "Password"
strBuff = ""
For i = 1 To Len(strText)
c = Asc(Mid(strText, i, 1))
c = c + Asc(Mid(strPwd, (i Mod Len(strPwd)) + 1, 1))
strBuff = strBuff & Chr(c And &HFF)
Next
Encrypt = strBuff
End Function
 
'*******************************
' VARIABLEs TO USE ON THIS PAGE
''myConn = "" 'Your DB connection string or name, NO quotes on variables
 
mySrc = "memb" 'The NAME of your USERS or MEMBERS Table you are validating against
myUsers = "usr" 'The NAME of your DB column for USERS in your MEMBERS/USERS Table
myPassName = "pwd" 'The NAME of your DB column for PASSWORD
''myCookieLib = "" 'The LIBRARY or TOP name of your members cookie to be set
myGoToUrl = "recipe-index.asp" 'WHERE members go to with a successful LogIn
 
sendPass = Request.Form("sendpass")
 
if sendPass <> "" Then
'*******************************
login = Request.Form("login")
 
 
set getUsr = Server.CreateObject("ADODB.Recordset")
getUsr.ActiveConnection = myConn
getUsr.Source = "SELECT pwd FROM memb WHERE usr = '" & login & "'"
getUsr.CursorType = 0
getUsr.CursorLocation = 2
getUsr.LockType = 3
getUsr.Open()
 
if NOT getUsr.EOF Then
thePass = getUsr("pwd")
End if
 
getUsr.Close
 
 
'------------------
' TO GF
'------------------
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.RemoteHost = "vopmail.netos.com" ' Specify a valid SMTP server
Mailer.AddRecipient "","" & login & "" 
'Mailer.AddRecipient "Yvonne Gifford","yvonne@harborgraphicdesign.com" 
'Mailer.AddRecipient "Jessica Hale","jessica.hale@attbi.com" 
 
Mailer.FromAddress = "memberinfo@glutenfreeda.com"  
Mailer.FromName = "Glutenfreeda Customer Care" 
 
Mailer.Subject = "Your membership password." 
 
'if Request.Form("mailtype") = "html" Then
'Mailer.ContentType = "text/html"
 
mailbody = mailbody & "The password for member " & login  & " is:" & vbcrlf & vbcrlf
 
if thePass <> "" Then
mailbody = mailbody & thePass  & vbcrlf & vbcrlf
Else
mailbody = mailbody & "We could not find a password for the username you provided.  Please check your information and try again." & vbcrlf & vbcrlf
End if
 
mailbody = mailbody & "If you continue to experience trouble signing in, please contact jessica@glutenfreeda.com"
 
 
Mailer.BodyText = mailbody
 
if Mailer.SendMail then
else
 'Response.Write "Mail send failure. Error was " & Mailer.Response 
'Response.Write Mailer.GetTempPath
end if
'------------------
 
'Response.Write login & "<br>"
'Response.Write thePass
 
Response.Redirect "membership-boa.asp?mail=sent"
 
'-----------------------
Else
 
'*******************************
' START THE LOG IN
'*******************************
 
'on error resume next
if Not Request.Form("login") = "" Then
 
'1. Look for the usrname and log-in if it exists
Dim login, password, getUsr, logError, security
login = Request.Form("login")
password = Request.Form("password")
 
set getUsr = Server.CreateObject("ADODB.Recordset")
getUsr.ActiveConnection = myConn
getUsr.Source = "SELECT * FROM " & mySrc & " WHERE " & myUsers & " = " & "'" & login & "'" & "AND " & myPassName & " =" & "'" & password & "'" & " AND active = 1"
getUsr.CursorType = 0
getUsr.CursorLocation = 2
getUsr.LockType = 3
getUsr.Open()
 
'2. If The USR exists, write the cookie, and redirect
if getUsr.EOF Then
'Send the User Back to the home page with error message?
Response.Redirect("membership-boa.asp?logError=1&usr=" & login & "")
Else
thisUsr = getUsr("m_id")
'Log the user in and go back to the home page, with welcome message
Response.Cookies("Glutenfreeda")("logged") = Encrypt(thisUsr)
Response.Cookies("Glutenfreeda").Expires = Now()+7
getUsr.Close
Response.Redirect(myGoToUrl)
End if
End if
 
 
End if

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of davemchale
davemchale

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
also, is it possible that your browser is caching the original login form and perhaps you're not seeing what you want to when you go back there due to the caching issue of that script in your browser?
Avatar of docmeat

ASKER

Thank you davemchale, you are awesome and your solution worked perfectly!  I cannot thank you enough!