Dynamically add posted form items into array

Discussion in 'ASP General' started by Daniel Gormley, Dec 14, 2005.

  1. What I have is a form that is dynamically generated based on which
    database table its calling. Therefore, the number of category.name.count
    can be different.

    So I have this form generated and say with x amount of input boxes.. I
    enter data in the boxes and submit.

    The data submitted is needing to be placed into an array for insert into
    a database.

    The code I have so far is this:

    <%
    Response.Write ("Form Data: " & Request.Form & "<br/>")

    If Request.Form("updateTable") <> "" then
    For Each Item In Request.Form
    x = Item
    y = Request.Form(Item)
    Response.Write "Item: " & X & " - " & Y & "<br/>"
    Next

    '###############################
    '##### Unfinised SQL Query #####
    SQL = "INSERT INTO '" & updateTable & "' SET "
    '###############################

    End If

    if Request.Form("table") = "" then

    Else
    Response.Write "<br/><br/>"
    tablename = Request.Form("table")

    Call OpenDB()

    SQL = "SELECT * FROM tbl" & tablename
    Set RS = CN.Execute(SQL)
    Response.Write "<form method=""post"" action=""index.asp"">"
    Response.Write "<input type=""submit"" value=""Submit"" name=""B1"">" &
    vbCrLf
    Response.Write "<input type=""hidden"" name=""updateTable"" value=""tbl"
    & tablename & """ />" & vbCrLf
    Response.Write "<table border=""1"" cellpadding=""5"">" & vbCrLf
    Response.Write "<tr>" & vbCrLf

    for each Category in RS.fields
    Response.Write "<td><b>" & Category.name & "</b></td>" & vbCrLf
    next

    col = Rs.Fields.Count

    Response.Write "</tr>" & vbCrLf
    Response.Write "<tr>" & vbCrLf

    for each Category in RS.fields
    Response.Write "<td><input type=""text"" name=""" & Category.name & """
    size=""20"" /></td>" & vbCrLf
    next
    Response.Write "</tr>" & vbCrLf

    If RS.EOF Then
    Response.Write "<tr>" & vbCrLf
    Response.Write "<td colspan=""" & col & """ align=""center"">" & vbCrLf
    Response.Write "No records matched!<br/> Number of Fields: " & col
    Response.Write "</td>" & vbCrLf
    Response.Write "</tr>" & vbCrLf
    Response.Write "</table>" & vbCrLf
    Response.Write "</form>"
    Else
    alldata = RS.GetRows
    End If
    Call CloseDB()
    %>

    Im kinda lost as to how to get the form data into an array where I can
    do my SQL query...

    *** Sent via Developersdex http://www.developersdex.com ***
    Daniel Gormley, Dec 14, 2005
    #1
    1. Advertising

  2. Daniel Gormley

    Steven Burn Guest

    If Request.Form("updateTable") <> "" then
    For Each Item In Request.Form
    x = Item
    y = Request.Form(Item)
    If Len(arrItems) > 0 Then
    arrItems = arrItems & ",," & X & " - " & Y '// Seperate with
    double comma
    Else
    arrItems = X & " - " & Y '// Seperate with double comma
    End If
    Next

    --
    Regards

    Steven Burn
    Ur I.T. Mate Group
    www.it-mate.co.uk

    Keeping it FREE!

    "Daniel Gormley" <> wrote in message
    news:OV$...
    > What I have is a form that is dynamically generated based on which
    > database table its calling. Therefore, the number of category.name.count
    > can be different.
    >
    > So I have this form generated and say with x amount of input boxes.. I
    > enter data in the boxes and submit.
    >
    > The data submitted is needing to be placed into an array for insert into
    > a database.
    >
    > The code I have so far is this:
    >
    > <%
    > Response.Write ("Form Data: " & Request.Form & "<br/>")
    >
    > If Request.Form("updateTable") <> "" then
    > For Each Item In Request.Form
    > x = Item
    > y = Request.Form(Item)
    > Response.Write "Item: " & X & " - " & Y & "<br/>"
    > Next
    >
    > '###############################
    > '##### Unfinised SQL Query #####
    > SQL = "INSERT INTO '" & updateTable & "' SET "
    > '###############################
    >
    > End If
    >
    > if Request.Form("table") = "" then
    >
    > Else
    > Response.Write "<br/><br/>"
    > tablename = Request.Form("table")
    >
    > Call OpenDB()
    >
    > SQL = "SELECT * FROM tbl" & tablename
    > Set RS = CN.Execute(SQL)
    > Response.Write "<form method=""post"" action=""index.asp"">"
    > Response.Write "<input type=""submit"" value=""Submit"" name=""B1"">" &
    > vbCrLf
    > Response.Write "<input type=""hidden"" name=""updateTable"" value=""tbl"
    > & tablename & """ />" & vbCrLf
    > Response.Write "<table border=""1"" cellpadding=""5"">" & vbCrLf
    > Response.Write "<tr>" & vbCrLf
    >
    > for each Category in RS.fields
    > Response.Write "<td><b>" & Category.name & "</b></td>" & vbCrLf
    > next
    >
    > col = Rs.Fields.Count
    >
    > Response.Write "</tr>" & vbCrLf
    > Response.Write "<tr>" & vbCrLf
    >
    > for each Category in RS.fields
    > Response.Write "<td><input type=""text"" name=""" & Category.name & """
    > size=""20"" /></td>" & vbCrLf
    > next
    > Response.Write "</tr>" & vbCrLf
    >
    > If RS.EOF Then
    > Response.Write "<tr>" & vbCrLf
    > Response.Write "<td colspan=""" & col & """ align=""center"">" & vbCrLf
    > Response.Write "No records matched!<br/> Number of Fields: " & col
    > Response.Write "</td>" & vbCrLf
    > Response.Write "</tr>" & vbCrLf
    > Response.Write "</table>" & vbCrLf
    > Response.Write "</form>"
    > Else
    > alldata = RS.GetRows
    > End If
    > Call CloseDB()
    > %>
    >
    > Im kinda lost as to how to get the form data into an array where I can
    > do my SQL query...
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    Steven Burn, Dec 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    0
    Views:
    310
    Andy Fish
    Nov 4, 2004
  2. Waldy

    Posted Form Items not in Request

    Waldy, Apr 8, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    370
    Mark Fitzpatrick
    Apr 8, 2008
  3. Brian Burgess

    Session objects and POSTed Form items

    Brian Burgess, Aug 30, 2003, in forum: ASP General
    Replies:
    9
    Views:
    146
    Brian Burgess
    Aug 31, 2003
  4. Brian J. Matuschak
    Replies:
    6
    Views:
    221
    Larry Bud
    Oct 26, 2006
  5. ela
    Replies:
    12
    Views:
    345
    Uri Guttman
    Apr 6, 2009
Loading...

Share This Page