Form object, and the element index

Results 1 to 3 of 3

Thread: Form object, and the element index

  1. #1
    Stuart Williams Guest

    Default Form object, and the element index

    *<BR>I first started a simple project that I thought I could knock out in a few minutes. The result is taking me almost 3 days! I have some questions, that I haven&#039t been able to resolve over the last few days about the form object in ASP and the object&#039s index.<BR><BR>I am posting a form to an ASP file that then generates an encrypted email. Simple. That works. But I don&#039t get away that easy!<BR><BR>When the certificate user gets the ASP generated email, I&#039ve created the body variable to include all of the form fields and their values with a very simple for loop.<BR><BR>Now, the problem is that I must print the <BR>form_element_name:form_element_value<BR>in the body of the email.<BR><BR>Still simple, and it works... but the elements aren&#039t being printed in the indexed order that they&#039re posted. How can I get the elements to be printed in that order, and ALSO display the element name, in addition to the value? I can easily create a for i=0 to Request.Form.Count loop that will print the INDEX number and the element value in the CORRECT order (without the element name), or conversely the element name and the value in the WRONG order with a for each item in Request.Form. How do i get the best of both worlds, with the item name and the form value in the correct indexed order?<BR><BR>One final thing: I tried adding the elements to a dictionary, but without the ability to assign the index value to a key or variable, I can&#039t order them along with the element name and value in the dictionary object. *sigh* <BR>HELP!<BR><BR>Thanks!<BR>Stuart<BR>

  2. #2 Guest

    Default RE: Form object, and the element index

    Because, for whatever reason, the Request object DOES NOT order the items in a form. Yes that stinks! But there are ways around it. Just yesterday I created some code that did just that. In my solution I used a database table to dump all of the fields from my form. Here is how I would solv this "Sorting" issue with the Request object without using a database.<BR><BR>The first step is how you name the fields on the form. They will need to match the array you setup below. In your case the sorting can/should be accomplished by using an array to store the sort order of the fields. (i didn&#039t test this so please let me know if you can&#039t fix it:-))<BR><BR>&#039START<BR>Dim strFields<BR>Dim arySortOrder<BR>Dim objField<BR>Dim objSortedFields<BR>Dim intCount<BR>Set objSortedFields = Server.CreateObject("Scripting.Dictionary")<BR><BR >strFields = "Name&#124Addr1&#124Addr2&#124City&#124State"<BR>a rySortOrder = Split(strFields,"&#124",-1,1)<BR><BR>For Each objField In Request.Form <BR> For intCount = 0 To (uBound(arySortOrder)-1)<BR> If objField = arySortOrder(intCount) Then<BR> objSortedFields.Add objField, Request.Form(objField)<BR> End If<BR> Next<BR>Next<BR><BR>&#039 Dictionary Object should now contain the fields in the sort order you setup.<BR>&#039 Now just to see it print it out<BR><BR>For Each objField In objSortedFields<BR> Response.Write objField & "=" & objSortedFields(objField) & "<BR>"<BR>Next<BR><BR>&#039 Hope this has helped and worked. <BR><BR>Set objSortedFields = Nothing<BR>&#039END<BR><BR>Good Luck,<BR>CodeMonkey:=

  3. #3
    Ryan S Guest

    Default RE: Form object, and the element index

    Stuart,<BR><BR> Here&#039s an interesting solution. Include the order you want them to appear in the actual form field name.<BR><BR>Such as:<BR><BR> 1.First_Name, 2.Last_Name, etc<BR><BR> Then do a quick sort using some of the OOOLLLD sorting methods that Scott has up here (go to the webtech archives from 99. They were some of the first few articles here).<BR><BR> That&#039s just one possible solution.<BR><BR>God bless<BR> Ryan<BR><BR>

Posting Permissions

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