dcsimg

Creating Dynamic Forms Page 6

By ServerWatch Staff (Send Email)
Posted Jan 11, 1999


This page takes each component of the the new_tran2.asp page and inserts it into the components table. The trick is traversing the request collection since the number of request items can be different for any transaction. Also the submit and reset buttons are part of the collection sent to this page, so we must make sure we have logic to handle or else they will be inserted into the database.

<title>NEW TRANSACTION <%=SESSION("NAME")%></title>

</head>

<h1 align="center"><font color="#0000FF">NEW TRANSACTION</font></h1>

<%
Set count = Server.CreateObject("ADODB.Connection")
DB_PATH = SERVER.MAPPATH("/DB")
CONNECT_STR  =  "FILEDSN=" & DB_PATH & "\DB.DSN;" & _
"DBQ=" & DB_PATH & "\WEBDB.MDB;"
count.Open CONNECT_STR
'get a connection to the db
set countrs = Server.CreateObject("ADODB.RecordSet")
NBR_OF_ITEM = 0
'every 3 items makes one component

For Each item In Request.Form() 
'traverse the Request items
      if (item <> "B1") AND (item <> "B2") then 
'dont process the buttons
          NBR_OF_ITEM = NBR_OF_ITEM + 1
          IF MID(ITEM,1,1) = "N" THEN
               MY_NAME = (request.form(item))
          ELSE
          IF MID(ITEM,1,1) = "P" THEN
               MY_POSITION = (request.form(item))
          ELSE
              MY_LENGTH = request.form(item)
          END IF
          IF NBR_OF_ITEM = 3 THEN
              NBR_OF_ITEM = 0 
          END IF
          END IF
'every 3 items do an insert into components
          IF NBR_OF_ITEM = 0 THEN
               SQL = "INSERT INTO COMPONENTS (TR_TRAN_ID, TR_POSITION, " & _                  "TR_LENGTH," & _
               "TR_NAME) VALUES (" & SESSION("NEW_TRAN_ID") & ", " & _
               MY_POSITION & ", " & MY_LENGTH &", '" & MY_NAME & "')"
  
              countrs.Open sql, count, 3 , 3, 1
          END IF
        END IF
Next
%>

<%=SESSION("NAME")%> COMPONENTS HAVE BEEN ADDED!

Working example

Page 6 of 6


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.


 

 


Thanks for your registration, follow us on our social networks to keep up-to-date