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

passing data through forms 1

Status
Not open for further replies.

SirLars

Technical User
Oct 24, 2000
47
CA
i am a beginner programmer and i am working on a project for an 8 player elimination tournament

i collect by form the 8 teams of two players entered in the tournament on a page called (admin8.asp)

(the form fields are
T1 for team1name
T1P1 for team 1 player 1,
T1P2 for team 1 player 2...etc..)

and passes them to the next page (round1.asp) using the <%=Request(&quot;T1&quot;)%> etc.. for the next form...
when this page is posted to (round1.asp) then writes an html page of the 8 players in the tournament.... (results.htm)

then a form using radio buttons for each game (R1G1,R1G2 etc) is used to decide who to POST to the next page (round2.asp) (and REwrite results.htm using the same script as begins round1.asp)

this seems to be where i'm running into a problem because i also need to pass on the results of the OLD form on (admin8.asp) to the next form page as well (so that the results.htm page can be properly REwritten)

i use the following at the beginning of the round2.asp page

<%

if Request(&quot;R1G1&quot;) = &quot;1&quot; then
R2T1 = Request(&quot;T1&quot;)
else
R2T1 = Request(&quot;T2&quot;)
end if

if Request(&quot;R1G2&quot;) = &quot;1&quot; then
R2T2 = Request(&quot;T3&quot;)
else
R2T2 = Request(&quot;T4&quot;)
end if

if Request(&quot;R1G3&quot;) = &quot;1&quot; then
R2T3 = Request(&quot;T5&quot;)
else
R2T3 = Request(&quot;T6&quot;)
end if

if Request(&quot;R1G4&quot;) = 1 then
R2T4 = Request(&quot;T7&quot;)
else
R2T4 = Request(&quot;T8&quot;)
end if

%>

but when i use <% =Request(&quot;R2T2&quot;) %> the results are not printed in the form-table?

what am i doing wrong?


 
If I understand your question correctly, then you basically have a page flow such as

1 --> 2 --> 3

and you have values on 1 that you need to be able to access on 3 --

If I'm wrong, then stop right here. If not, read on.

The most &quot;sophmoreish&quot; (my boss's term) way to do this is to place the values that you are receiving into hidden form variables on 2 and then when you submit that form, you will be able to pick those variables up on 3 using the same method you have above. One small change, though, you should be qualifying your request method up there by asking for request.form (for &quot;post&quot;), and request.querystring (for &quot;get&quot;) -- post and get referring to the method that you specify in your <form> tag...

<input type=hidden name=elementName value=<%=request.form(&quot;elementName&quot;)%>>

If you play around with this method, you will get a very good feel of how forms interract with pages, and I think it's a good exercise to go through. That being said, a 'better' way to do it is:

set session variables. This is a way to introduce &quot;state&quot; into your application, whereas on regular asp pages that don't use such a method are &quot;stateless&quot;, and therefore can't &quot;remember&quot; what variables are once the page has been rendered to the browser.

To set a session variable, use:
session(&quot;varName&quot;) = variable

and to pick them up, use:
variable = session(&quot;varName&quot;)

These variables have a life of 20 minutes unless you explicitly set it otherwise with the session.timeout method.

let me know if this helped. :)
Paul Prewett
 
yes very helpful thanks... :)

but i am now having problems with the second round and passing information to the third page

i am using the hidden values and passing them on to the next form.. as per your suggestion...

but it seems to be truncating the strings for some reason...
and losing the values to these variables..

(i.e. &quot;team 2&quot; is reduced to &quot;team&quot;, &quot;the champs&quot; is reduced to &quot;the&quot;.. etc..)
also doesn't seem to want to pass ANY variables into the tables for the next rounds.. but it is writing the data to the results.htm file..

do i need to rename the variables used?
is this statement wrong?

<input type=hidden name=T1 value=<%=request.form(&quot;T1&quot;)%>>

i.e. i wanna use the same varable name throughout

i am concerned about using a session variable if the value is only good for 20 minutes.. as the average length of time between rounds will be longer than that..

i.e. the person running the tournament will have that page open for up to 30 minutes per round...

thanks for your help.. i am enjoying this learning process..

Lars
 
Yes, a friend of mine was actually having the exactly the same problem just the other day...

If anyone knows how to avoid this in a better way than what I am about to suggest, please post it up -- otherwise, Lars, here is what we did to solve that problem --

There is a function called replace in vbscript -- it will search through a string, find what you tell it to, and replace it with what you tell it to...

We narrowed down the problem to where you reassign it to a hidden variable -- for some reason, it just loses everything to the right of the first space --

say we have an element name called 'name' and it's a full name (spaces and all) -- here is how we assigned it to the hidden form variable --

dim str
str = request.form(&quot;name&quot;)
str = replace(str, &quot; &quot;, &quot;_&quot;)
response.write(&quot;<input type=hidden name=name value=&quot; & str & &quot;>&quot;)

So then, if the name was Jon Doe, Jr
then the form variable now has Jon_Doe,_Jr in it, and then you just run the opposite procedure on it to take out the underscores --

dim str
str = request.form(&quot;name&quot;)
str = replace(str, &quot;_&quot;, &quot; &quot;)

so now you have your original value back in 'str'

It seems like a hack to me, but hey... whatever works, right? ;-)

keep me posted.
paul
 
actually paul.. that problem i fixed almost right away..

i noticed that when i checked the source on my browser it was putting the values in for
<input type=hidden name=T1 value=<%=request.form(&quot;T1&quot;)%>>
as (when t1=&quot;the champ&quot;)
<input type=hidden name=T1 value=the champ>
so i just added quotes around the &quot;<% code %>&quot; and it seemed to work.. but i am still having problems transfering the values to the 3rd page..

the reason i used the hidden form tag was to ask if i was in err declaring a variable as the same name...

do i need to make it
<input type=hidden name=newT1 value=&quot;<%=request.form(&quot;T1&quot;)%>&quot;>

or can i declare T1 to be the same as the &quot;old&quot; T1...
 
No, you should be able to declare them to be the same name if you want. That should work just fine --

Good one on the fix and the quotes. ;-)

A good way to fake a debugger in script is to response.write the values wherever you want to put a checkpoint. That should help track down where you are losing the value --

Put one as soon as you get on the page, after you assign it to the new element, and then when you get to the page you are trying to pick it up on -- that should get you going again.
 
thanks alot.. actually i'm embarrassed to admit it was a silly error on my part.. forgot to dim the variables as i introduced them... forgot they were not part of the original form...

but i still want to say thanks alot
i just finished and it is working ok... you saved the last few hairs on my head....

next project... dynamic csv database for round robin tournaments...

i'm sure i'll be back here soon.... ;)

Lars

sirlars@bestplayers.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top