SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Read NULL value parameters from POST and GET in classic ASP

    Hi

    I'm try to achieve in classic asp what has been done here in ASP.NET

    http://stackoverflow.com/questions/4...ring-parameter

    So if i have a page question.asp

    <form action="result.asp" method="POST">
    Name: <input type="Text" name="name" maxlength="30"><BR>
    Age: <input type="Text" name="age" maxlength="10"><BR>
    Sex: <input type="Text" name="Sex" maxlength="10"><BR>
    <input type="Submit" name="submit" value="submit"><BR>
    </form>

    And nothing is input in e.g. 'Sex' text box I stil need to know that it was sent. e.g. name=karl&age=39&sex=

    Thanks

  2. #2
    SitePoint Zealot gidday's Avatar
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi bendecko

    So maybe something like

    If Request("sex") = "" Then
    'do something because sex is empty
    Else
    'do something else because sex is androgynous
    End If
    Joe
    "All that is necessary for the triumph of evil
    is that good men do nothing."

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Consider also the IsEmpty() and IsNull() functions.
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Member
    Join Date
    May 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys,

    Sorry my example was poor.

    As in the .net query, I don't know what parameters are on the submitting form so I can't test e.g sex="" or null or whatever.

    I need to detect the parameters from the querystring that are null or have no value without knowledge of the form post variables in advance.

    Thanks

  5. #5
    SitePoint Zealot gidday's Avatar
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try

    For each x in Request.Form
    Response.Write("<br>" & x & " = " & Request.Querystring(x))
    Next
    Joe
    "All that is necessary for the triumph of evil
    is that good men do nothing."

  6. #6
    SitePoint Member
    Join Date
    May 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks gidday, unfortunately, no it doesn't work.

    If a form item e.g. text box is empty it doesn't appear in the list.

  7. #7
    SitePoint Zealot gidday's Avatar
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post your code for your form?
    Joe
    "All that is necessary for the triumph of evil
    is that good men do nothing."

  8. #8
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What if you replace .Form with .QueryString?
    Ian Anderson
    www.siteguru.co.uk

  9. #9
    SitePoint Zealot gidday's Avatar
    Join Date
    Jan 2007
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoops. My bad.
    Joe
    "All that is necessary for the triumph of evil
    is that good men do nothing."

  10. #10
    SitePoint Member
    Join Date
    May 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <html>
    <body><%
    For each x in Request.Form
    Response.Write("<br>" & x & " = " & Request.QueryString(x))
    Next
    %>

    <form action="sitepointdemo.asp" method="post">
    <input name="demo" type="text" />
    <input name="radio" type="radio" value="home">
    <input name="radio" type="radio" value="away">

    <input name="alive" type="checkbox" value="yes">
    <input name="submit" type="submit" /></form>

    </body>
    </html>


    If I don't tick e.g. the checkbox it doesn't show up in the posted values.

    Thanks for your help!

    Bendecko

  11. #11
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Checkboxes that are not checked are not sent with the form, so ASP cannot see them. If you know they exist in the form then you can test for them explicitly, otherwise you're stuck.
    Ian Anderson
    www.siteguru.co.uk

  12. #12
    SitePoint Addict itHighway's Avatar
    Join Date
    Jan 2008
    Location
    GUJ
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change following line
    <form action="result.asp" method="POST">
    to
    <form action="result.asp" method="GET">

  13. #13
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,608
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If method is POST use Request.Form

    If method is GET use Request.Querystring

    But either way, if a checkbox is not checked then it is not sent with the form - period.
    Ian Anderson
    www.siteguru.co.uk

  14. #14
    SitePoint Member
    Join Date
    May 2011
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah it seems the browser doesn't bother sending checkboxes if they are not checked. So nothing can be done about that on the asp side.

    Thanks for your help guys.

    The work around is to use javascript. Or to add a hidden field with the same name set to 'OFF' or whatever negative you using.

    The POST results then are either checkbox=OFF (for no check box tick) or checkbox=OFF, ON which you can read for.

    Thanks

    Bendecko


Bookmarks

Posting Permissions

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