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!

Passing variables from an initial page to a second and then third page

Status
Not open for further replies.

ma701sd

IS-IT--Management
Dec 15, 2000
94
GB
Hi,
Sorry, this is long one!

I'm trying to create a login procedure with the facility whereby if a password is forgotten, users can enter their username and surname to retrieve their password reminder question. This bit is OK!
On the action pag where the users question is displayed (or not in the case of not a valid user) I provide a form field where the user can enter their answer. The problem I'm having is that the second action page (GetpasswordreminderAnswer.cfm) displays all records.

I have tries to pass the hidden form from the initial page to the second and third action page but it doesnt seem to be passing it in. I get the error #Form.userName# not valod blah blah.

Can anyone help as tjis really getting on my nerves??

Many thanks

Sam
 
You may want to put the Username in a session variable, ie. on page 2, put <cfset Session.Username = &quot;#Form.Username#&quot;>.

Otherwise, make sure you have all your boxes (hidden and text) within the <form> tag, and make sure the text box has name=&quot;username&quot;.

Page 1:

<form action=&quot;page2.cfm&quot; method=&quot;post&quot;>
<input type=&quot;text&quot; name=&quot;username&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
</form>

Page 2:

<cfquery name=&quot;getquestion&quot; datasource=&quot;DBConn&quot;>
SELECT Question FROM Question_Table
WHERE Username = #Form.Username#
</cfquery>

<form action=&quot;page3.cfm&quot; method=&quot;post&quot;>
<input type=&quot;hidden&quot; name=&quot;username&quot; value=&quot;#Form.Username#>
<cfoutput query=&quot;getquestion&quot;>
#Question#
</cfoutput>

Answer:
<input type=&quot;text&quot; name=&quot;answer&quot;>
<input type=&quot;submit&quot; value=&quot;Submit&quot;>
</form>

Page 3:

<cfquery name=&quot;getanswer&quot; datasource=&quot;DBConn&quot;>
SELECT Answer FROM Question_Table
WHERE Username = #Form.Username#
</cfquery>
blah, blah, blah

Hope this helps! If not, you may want to include some code so that we can see what's going on..

Bobby R


 
Hi Bobbyr,

Many Thanks for your response..It does not give me the &quot;from.UserName&quot; error but now i seem to get a different error message.
Basically i've put Vaidation into the the first name i.e. if Username and password is true then display &quot;passwordreminderquestion&quot; else error,however, if i enter a valid username and password and get the correct question - to which I reply, it tells me that no such user exists yet the validation is the same as before i.e. extract the unique user I entered.


Im attaching the code for the three pages, its long so I hop you dont mind (You did say to attach code :) )

ForgottenPassword.cfm
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>

<HTML>
<HEAD>
<TITLE>Forgotten Password</TITLE>
</HEAD>

<BODY>
<CFFORM ACTION=&quot;getPasswordReminderquestion.cfm&quot; METHOD=&quot;POST&quot;>

For us to be able to locate your password, simply supply your username and email address in the boxes below:<BR><BR>


Please enter your user name:
<CFINPUT TYPE=&quot;Text&quot; NAME=&quot;UserName&quot; REQUIRED=&quot;YES&quot; MESSAGE=&quot;Please Enter a UserName&quot;><BR>
Please enter your Last Name:
<CFINPUT TYPE=&quot;Text&quot; NAME=&quot;SurName&quot; REQUIRED=&quot;YES&quot; MESSAGE=&quot;Please Enter your Last Name&quot;><BR>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;process&quot;>
<INPUT TYPE=&quot;reset&quot; VALUE=&quot;Clear&quot;><BR>
</CFFORM>


</BODY>
</HTML>

GetpasswordReminderquestion.cfm
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>



<!-- This is the origina password reminder where I attempted to rtrieve the users password reminder question and submit
The answer to another form. Instead I opted to just the question which the user should be able to answer at the login screen-->

<CFQUERY DATASOURCE= &quot;ONLINE&quot; NAME=&quot;Retrieve_Question&quot;>
SELECT Username, Email, PasswordReminderQuestion,PasswordReminderAnswer, Surname
FROM Users
WHERE UserName = '#Form.UserName#' AND SurName= '#form.SurName#'

</CFQUERY>

<HTML>
<HEAD>
<TITLE>Retrieve Member login details</TITLE>
</HEAD>

<BODY>

<CFIF #Retrieve_Question.RecordCount# IS 0>

<CFOUTPUT>
Im Sorry, the name <B>#UserName#</B> and Last Name <B>#SurName#</B> that you entered does not match a valid user.<BR>
You need to either <A href=&quot;NewUser.cfm&quot;> create an account </A> or
<A href=&quot;ForgottenPassword.cfm&quot;> Try again</A> </CFOUTPUT>

<CFELSE>
<CFFORM ACTION = &quot;GetPasswordReminderAnswer.cfm&quot; METHOD =&quot;POST&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;UserName&quot; VALUE=&quot;#FORM.UserName#&quot;>
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;SurName&quot; VALUE=&quot;#FORM.SurName#&quot;>


<CFOUTPUT QUERY = &quot;Retrieve_Question&quot;>
Your User Name is #UserName#<BR>
Your Last Name is #SurName#<BR>

Your Password Reminder Question is #PasswordReminderQuestion#<BR>

Please Enter your answer to the question:
<CFINPUT MESSAGE=&quot;You must enter your answer&quot; REQUIRED = &quot;Yes&quot; TYPE=&quot;Text&quot; NAME=&quot;PasswordReminderAnswer&quot;>
<INPUT TYPE=&quot;submit&quot; VALUE=&quot;process&quot;>
<INPUT TYPE=&quot;reset&quot; VALUE=&quot;Clear&quot;><BR>

</CFOUTPUT>

</CFFORM>

</CFIF>

</BODY>
</HTML>


Getpasswordreminderanswer.cfm
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>


<CFQUERY DATASOURCE= &quot;ONLINE&quot; NAME=&quot;Retrieve_Password&quot;>
SELECT UserName, Password, Email, PasswordReminderQuestion, PasswordReminderAnswer, Surname
FROM Users
WHERE UserName = '#FORM.UserName#' AND SurName= '#form.SurName#'


<!--- It doesnt get hidden form field from the previous page
WHERE UserName = '#Form.UserName#' --->

</CFQUERY>

<HTML>
<HEAD>
<TITLE>Retrieve Password</TITLE>
</HEAD>

<BODY>

<CFIF #Retrieve_Password.recordcount# is 0 >
<CFOUTPUT>
Im Sorry, the answer <B>#PasswordReminderAnswer#</B> to your question is invalid.<BR>
You need to either <A HREF=&quot;NewUser.cfm&quot;> create an account </A> or
<A HREF=&quot;ForgottenPassword.cfm&quot;> Try again</a>
</CFOUTPUT>

<CFELSE>

<CFOUTPUT QUERY = &quot;Retrieve_Password&quot;>

You may now log in with the following details:<BR>
User Name : <B>#UserName#</B>
Password : <B>#Password#</B><BR><BR>
</CFOUTPUT>
</CFIF>
</BODY>
</HTML>


This is really starting to cheese me off coz just when I thought I understood SQL this happens. My understanding is that if I create a search where username =username and password=password then surely only one record is matched yet CF says it zero recordcounts???

Im really sorry, I know this is long.

Your help will be greatly appreciated

Many thanks and best regards

Sam

PS - The code is a bit raw and messy so please excuse




 
try to display the values of form.surname and form.username in the getpasswordreminderanswer page
i guess that they are somehow wrong (i bet it's #form.username# that is dislayed instead of the value), that's why you don't get an answer from the db
this comes from on the previous page you don't include them within cfouput
buti'm not 100 % sure

 
There are ways to pass variables from page to page using hidden form fields.

The other approach is to build a &quot;dynamic form&quot; template, one in which the hidden fields get added dynamically. Take a look at this script if you have never done anything like this before...

 
Hi Iza,
Thanks for the reply, You are right, it does display it as #form.username# and #form.surname#

But, How would I correct this problem. Would it be possibe for you to tell me how to fix it. This has stumped me for a few days now!

Cfhub.com - Thanks for the reply, however when I click on the link, it cannot find the page..It gives a #Form.url# error.
 
you have to enclose the #variable# between <cfoutput> tags to get their VALUE passed
see this part :
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;UserName&quot; VALUE=&quot;#FORM.UserName#&quot;>
the value is #FORM.UserName#
if you want it to be the value of #FORM.UserName#, just use
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;UserName&quot; <cfoutput>VALUE=&quot;#FORM.UserName#&quot;</cfoutput>>
 
Thanks Iza for your help...
However, Im now encountering another problem :(

I created a new thread if you're interested

Thanks once again

Same
 
i haven't seen your new thread yet .. but i'm happy to have helped with this one :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top