...

View Full Version : form one post & one get pages, how to go to a page ? len(number) ?



lse123
08-10-2007, 10:24 AM
when I go to an asp page from two pages one via form-post and another via form-get , how [if contition] to know from where [post or get] I get to this page to get same var but with proper statement ?
May use len() to numberic fields ? To date ? How I compare two dates[must be same format or doesn't matter?] ?

Spudhead
08-10-2007, 01:18 PM
If you POST data from a form, it will appear in the request.form collection. If you GET the data it will appear in the request.querystring collection. Seeing as they're both part of the request object, if you're expecting a variable but don't know whether it's going to be coming from a GET or a POST, you can simply do request("myVariableName"), although be aware that you're then forcing your ASP server to go looking through all sorts and it'll have an effect on the page performance.

Use isDate() to see if VBscript can recognise a variable as a valid date. If it can, use cDate() to convert it to a VBscript date variable. You can then compare it to other date variables as much as you like.

I have no idea what "May use len() to numberic fields?" means :confused:

lse123
08-10-2007, 02:39 PM
when I get date from form field then I use isDate() after cdate() and after I do the comparison ?
May use (len(number)<1) to see eg if number defined ?

Spudhead
08-10-2007, 04:59 PM
dim strMyDate, dtMyDate
strMyDate = request.form("date_field")
if isDate(strMyDate) then
dtMyDate = cDate(strMyDate)
if dtMyDate < now() then response.write("That date is in the past")
if dtMyDate > now() then response.write("That date is in the future")
end if


If you want to see if a value passed through to your page is a number, you can use isNumeric() in the same way that you'd use isDate().

miranda
08-10-2007, 08:48 PM
Using Request and not specifying the collection will go through the collection in the following order

1. QueryString
2. Form
3. Cookies
4. ClientCertificate
5. ServerVariables

You will be returned the value of the first name key that is found.

Example
you are on the following page, somepage.asp?color=red&number=36
this page has this form
<form method="post" action="asppage.asp">
<input type="hidden" name="color" value="blue">
<input type="hidden name="number" value="75">
<input type="submit">
</form>
and Sets a cookie with color=yellow

when you click the button to process the page, you will find the following

Request("color") will return red
Request("number") will return 36
Request.Form("color") will return blue
Request.Cookies("color") will return yellow

glenngv
08-15-2007, 05:09 AM
Using Request and not specifying the collection will go through the collection in the following order

1. QueryString
2. Form
3. Cookies
4. ClientCertificate
5. ServerVariables

You will be returned the value of the first name key that is found.

Example
you are on the following page, somepage.asp?color=red&number=36
this page has this form
<form method="post" action="asppage.asp">
<input type="hidden" name="color" value="blue">
<input type="hidden name="number" value="75">
<input type="submit">
</form>
and Sets a cookie with color=yellow

when you click the button to process the page, you will find the following

Request("color") will return red
Request("number") will return 36
Request.Form("color") will return blue
Request.Cookies("color") will return yellow
Your whole idea is good but the querystring in the current page will not be present in the request when the page is submitted. So

Request("color") will return blue not red
Request("number") will return 75 not 36

You should have made the form like this (though normally you wouldn't do it like this) to correctly demonstrate your point.

<form method="post" action="asppage.asp?color=red&number=36">
<input type="hidden" name="color" value="blue">
<input type="hidden name="number" value="75">
<input type="submit">
</form>

miranda
08-17-2007, 05:04 AM
you are right i meant to put that in the form' action and it slipped by me. I have seen a number of instances where the developer did pass values in a url pointed to by the forms action. and then wondered why they recieved the wrong value after the form was processed when they did not specify the collection of the request object.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum