![]() |
![]() |
|
![]() |
Paradox Web Server Lesson 2 - Quick & Dirty Example © 2001 Tony McGuire Lesson 2 - Quick & Dirty Example Quick & dirty example of retrieving a whole slew of field values from an Internet form (taken from the Example that came with Paradox, with some of my own embellishments added): Assume that you have an Internet form with 20 fields that you use to collect data from the people who visit your site. This can be any data type you want (even memo). The method below could be used to take the data and populate a table. (One thing that I may have overlooked explaining. The Internet form you are using to collect data from your site's visitiors is not directly linked to the Paradox table, as a desktop form often is. The Internet form resides in the browser memory of your sites' visitors. Not until they click on the "submit" button is the link from their browser to your Paradox code established. Thus, you must first retrieve the information from the page the user was viewing, adding info to etc. before Paradox can make use of the information the visitor typed in.) method getallfields(var Request OleAuto, var Response OleAuto) Logical var tc tcursor dynvar dynarray[] anytype i,n number retvar string endvar n = Request.NFields - 1Here, you are setting n to the highest numbered field on the form. You subtract 1, because the first field on a form is 0. "for i from 0 to n" can then be used to reference getFieldName() and GetFieldByIndex() since this will then match with the starting field # (0) that appears on the form, as well as total # of fields. for i from 0 to n dynvar[ Request.GetFieldName(i) ] = ltrim(rtrim(upper(Request.GetFieldByIndex(i)))) endForRequest.GetFieldName(i) is get the name of each field and store it as the dynarray element name. Request.GetFieldByIndex(i) is get the value of each field. This matches each field's name with its value. You now have a dynamic array filled with field names and their values. Now open the table that is to receive the data. It just so happens that when we created the form on the Internet, we named the fields on the form with the same names as the fields in the table we will use to store the data that the user is inputting. Further, the table we are using to store the data has a primary key on fields "username" and "address". You would probably add a lot of validity checking at this point. tc.open("tblname.db") ;this could as easily open on a secondary index, tc.open("tblname.db","scndindx")And then qLocate() would apply to the secondary index (if you needed to allow duplicates, for example) at this point, your particular needs (and standard Paradox/OPAL techniques) apply. tc.edit() if not tc.qlocate(dynvar["username"],dynvar["address"]) then tc.insertrecord() endif if not tc.copyfromarray(dynvar) then ;statement back to user endif tc.endedit() tc.close()Build variable (retvar) containing return statement (in HTML) to user this could be a "data accepted" statement, or even another form for them to fill in (another post - later). response.resultstring=retvar return true endmethodI did the qlocate() in the event the key field(s) were already in the table; then this would be a record update rather than a new record (standard technique, no different on the Internet than on the desktop). In the copyfromarray(), Paradox _automatically_ matches the dynarray[] elements with the table's field names. If there are elements in the dynarray that don't match the table, they are ignored. If there are fields in the table with no matching dynarray element, the lack of match is also ignored. Thus, with a few lines of code we have retrieved a whole slew of data fields and posted them into a table. How much easier can it get? Once you get past how to retrieve the data, everything is the same old (wonderful) Paradox you have been using. There are definitely some do's and don't do's that apply specifically to Paradox-I, and many tables will have to be restructured to make Paradox blazingly fast in the Internet world; but many of these concepts will apply to the desktop as well. I have restructured most of the tables I use on the desktop to take advantage of the techniques I used learning about Paradox & the Internet (Paradox-I). Lesson 3 Discussion of this article |
![]() Feedback | Paradox Day | Who Uses Paradox | I Use Paradox | Downloads ![]() |
|
![]() The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation. Paradox is a registered trademark of Corel Corporation. ![]() |
|
![]() Modified: 15 May 2003 Terms of Use / Legal Disclaimer ![]() |
![]() Copyright © 2001- 2003 Paradox Community. All rights reserved. Company and product names are trademarks or registered trademarks of their respective companies. Authors hold the copyrights to their own works. Please contact the author of any article for details. ![]() |
![]() |
|