Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2004, 05:49 AM
Authorized User
 
Join Date: Aug 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default pass array? dynamic insertion?

Looking for your help

i'm doing an add.asp to add records to DB.
well, for i have many tables, in the add page, i won't know what field names will be. therefore, "dynamic insertion" required.

My purpose is here:
   every input field named as field.name which can be obtained by reading the DB first.
 for each field in Rs.fields
           response.write F.name
           response.write "<input type='text' name="& F.name &">"
       next
then submit the [form] to confirm.asp
      since have to retrieve the content of input, i do this
       request.Form(must write F.name) in confirm.asp
well, my page don't know what's the F.name in dynamic sense.
i think of one way :
read the DB once more, and retrieve the Field names
but this is expensive, or i don't want to do sth. like this

another way is:
store the field names in an array in an order, then pass the array to next page (e.g. using the hidden type) after that retrieve the filed name from the passed array and do request to get data

well, well, well. don't know how to pass array. i stored the array and for each element in the arry, i used hidden type. That means i still passeda individual value not an array. quite exhausted !!

[NOTE] I didn't use <input name="oneNameforall" type=text> for all the input areas in Add.asp. because index of collections will not exactly match the order that appears in the html form. using array to keep everything in order is wat I want.

any suggestions?
regds







 
Old August 11th, 2004, 06:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:...request.Form(must write F.name) in confirm.asp
You don't have to know the names, you can just iterate over the Form collection and build your insert accordingly. Something like this:
Code:
    For Each Key in Request.Form
        Fields = Fields & Key & ","
        Values = Values & "'" & Request.Form(Key) & "',"
    Next

    ' knock off the final comma
    Fields = Left(Fields, Len(Fields)-1)
    Values = Left(Values, Len(Values)-1)

    SQL = "INSERT yourtable (" & Fields & ") VALUES (" & Values & ")"

        ' code here to execute the SQL
 
Old August 11th, 2004, 09:06 PM
Authorized User
 
Join Date: Aug 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hmm... your idea quite valuable and i will use that in my Add_to_Db.asp
but, for Add_Confirm page, i need to display input which user typed in Add.asp and ask for confirmation. like
in Add.asp page

fieldName1 [text field1]
fieldName2 [text field2]
fieldName3 [text field3]
and in Add_confirm.asp page display should like this,
fieldName1 <text field1_value>
fieldName2 <text field2_value>
fieldName3 <text field3_value>
you see the order must be exactly matched.
so have to use an array? and how to?
thanks

 
Old August 12th, 2004, 03:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Why do you think the order will not be exactly matched? have you tried it? Bottom line, you cannot directly pass an array using http.





Similar Threads
Thread Thread Starter Forum Replies Last Post
xslt: pass index of array EefjeC XSLT 1 July 2nd, 2007 06:31 AM
Not able to pass array as an argument to Let Prope Kapil Access VBA 1 January 30th, 2007 09:30 AM
how to pass address of an array to a dll(in c++) iceman1188 General .NET 0 May 30th, 2004 09:19 PM
Pass an array between client and server pigtail Javascript 3 April 14th, 2004 12:42 PM
How do I pass a option button array John Pennington Beginning VB 6 1 March 5th, 2004 03:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.