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

passing a querystring within a form???

Status
Not open for further replies.

cloudseven

Programmer
Mar 16, 2003
18
0
0
CA
hi there, I'd downloaded a shopping cart script and I'm just playing around with it. It works great and adds the appropriate items, I'm having trouble passing a querystring which holds a value to redirect to a particular page. Here is some code...Any help would be great, I'm scratching my head...I'm sure it's just a small thing...THANKS IN ADVANCE!!!

FORM TO GET VALUES

<form name='frmProducts' method='post' action=&quot;shoppingCart.asp?action=add&iNum=<%=r(0)%>&user=<%=Request.Cookies(&quot;user&quot;)%>&cat=<%=request(&quot;cat&quot;)%>&quot;>

***some codes***

</form>

all these querystrings I can get except for request(&quot;cat&quot;).
The other values are in sub procedures and other functions and they work. I'm not sure if that's why request(&quot;cat&quot;) ain't working? I know it holds a value because I'd tested it with just a hyperlink instead within a form. On the shoppingCart.asp page I have this.


***********************

lots of code up here with subs and functions and intiation of a shoppingCart class

***********************

<html>
<head>
<title>The ASP Emporium - Shopping Cart Example</title>
</head>
<body bgcolor=&quot;#EEEEEE&quot;>
***EMBEDDED HTML FROM CODE ABOVE***
<%DisplayShoppingCart%>
<table width=100%>
<tr>
<td valign=right><a href=&quot;./products.asp?cat=<%=request(&quot;cat&quot;)%>&quot;>Continue Shopping</a></td>
</tr>
</table>
<br>
<br>
</body>
</html>
 
use Request.QueryString(&quot;cat&quot;) to request for the query string.
 
tried that too, doesn't work...thanks for your response tho!
 
can i see the code for your previous page?
 
I don't see the problem, but since you're posting a form anyway, why not use hidden fields? They're just as easy to implement and they don't end up in the user's shortcut/favorite URL if they add the page to their favorites.
 
hey whloo...I'm not at home now but will post it once I get home. Thanks.
 
hey there, I found my solution but still it's bugging me why the querystring isn't capturing the value? Anyhoo, I just assigned a session variable to request(&quot;cat&quot;) and reference the session variable when I need it.

***scratching head***
 
sorry, didn't catch this thread earlier. see you solced the problem though.

out of curiousity, have you tried to view the output of the .Write by view source in the HTML?
Just to ensure the code is generating the href accuratly.


____________________________________________________
[sub]$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;[/sub]
onpnt2.gif
[sub][/sub]
 
sorry, not quite sure what you mean? you mean in the shoppingCart.asp where I want to get the querystring? Did I check the output for request(&quot;cat&quot;)???
 
the page that you reference with the faulty url being generated by the response.write
in red
<tr>
<td valign=right><a href=&quot;./products.asp?cat=<%=request(&quot;cat&quot;)%>&quot;>Continue Shopping</a></td>
</tr>

right click the page and view the source.
does it actually output something like this
<tr>
<td valign=right><a href=&quot;./products.asp?cat=somecat&quot;>Continue Shopping</a></td>
</tr>

also, isn't that suupose to be a ../ for parent directory. just noticed the missing .
may be valid, just haven't used or seen it in a href with one

____________________________________________________
[sub]$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;[/sub]
onpnt2.gif
[sub][/sub]
 
hmmm...let me check...as for the directory thing, not sure, I'd dled this script from somewhere...I would like know what it is for a parent directory myself. Out of curiosity, what is this mean?

request.servervariables(&quot;SCRIPT_NAME&quot;)
 
request.servervariables(&quot;SCRIPT_NAME&quot;)
will give the virtual path to the script

the ../ means the referenced file in the href value is in located in the parent directory
reference the directory mapping

____________________________________________________
[sub]$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;[/sub]
onpnt2.gif
[sub][/sub]
 
hey onpnt, this is what displays under 'view source'. I'd tried using ./ and ../ for the parent directory and same thing!


<a href=&quot;../products.asp?cat=&quot;>Continue Shopping</a>
 
The generation in your previous scripts are not giving a value to the querystring. start a back-track and where ever you set this value test with a response.write of it after setting it.
The fact this string is completely blank as we see from the HTML generated says theres a error in previous pages.



____________________________________________________
[sub]$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;[/sub]
onpnt2.gif
[sub][/sub]
 
cloudseven, the answer is...

Unless I'm mistaken, you can't read data from both request.querystring AND request.form collections, you can only do one type OR the other type.

Hmm... I haven't ever tried to send both types at once. I would presume Request.ServerVariables(&quot;Request_Method&quot;) contains POST, not GET?

POST method using FORM submission is recommended unless you want to use hyperlinks or input buttons where GET method using QUERYSTRING is then appropriate. Form posting is also considered more secure since querystrings can be seen and even altered by the user. There is a practical limit to the length of the querystring since many browsers limit the length of the URL to about 1024 characters.

See also thread333-102124
 
you can send both and request both. at least I've done fairly often before without any problems. many times a action needs a querystring while the method of forms will be a POST. Then you will need to perform both requests

____________________________________________________
[sub]$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;[/sub]
onpnt2.gif
[sub][/sub]
 
onpnt, I won't doubt your experience. I stand corrected. There must have been something I thought you couldn't do. If it wasn't this, then it must have been the time I was trying to upload a file. The book cautioned that if I used Request.BinaryRead, then I couldn't do a Request.Form. One or the other, not both, though I think BinaryRead could get the form data too with extra coding. Upon further research we use <FORM enctype=&quot;multipart/form-data&quot;> on the first page and use a thirdparty control aspSmartUpload on the second page now.

Sorry for the confusion there.
 
the BinaryRead may cause concerns as you said. Thanks for the info so when I run into that I'll know what I did wrong [smile]

just for a little test try
<html>
<body>
<%
If request.QueryString(&quot;test&quot;) <> &quot;&quot;
Response.Write &quot;Form data passed by URL = &quot; & Request.QueryString(&quot;test&quot;) & &quot;<br>&quot;
Response.Write &quot;Form data passed by HTTP = &quot; & Request.Form(&quot;posted&quot;) & &quot;<br>&quot;
Else
%>
<form method=&quot;POST&quot; action=&quot;first.asp?test=querstring&quot;>
<input type=&quot;text&quot; name=&quot;posted&quot; value=&quot;data sent via HTTP&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
</form>
<% End If %>
</body>
</html>

call on first.asp

____________________________________________________
[sub]$str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
$Nstr = ereg_replace(&quot;sleep&quot;,&quot;coffee&quot;,$str); echo $Nstr;[/sub]
onpnt2.gif
[sub][/sub]
 
hey onpnt, I'd tested it already with a hyperlink containing the querystring request(&quot;cat&quot;) and I get the value on the second page. It's when I use it within the form that I can't get the value. I don't have it anywhere else on the products.asp page.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top