Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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?] ?

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    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

  • #3
    Regular Coder
    Join Date
    Dec 2005
    Posts
    702
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ?

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Code:
    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().

  • #5
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by miranda View Post
    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.
    Code:
    <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>
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •