Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

67 lines
2.3KB

  1. <%
  2. Class FormCache_Class
  3. 'given a form name and IRequestDictionary params (request.form) object, caches form values
  4. Public Sub SerializeForm(form_name, params)
  5. dim form_key, form_val, serialized_key
  6. For Each form_key in params
  7. form_val = params(form_key)
  8. serialized_key = CachedFormKeyName(form_name, form_key)
  9. 'put "serialize<br>"
  10. 'put "--form_key := " & form_key & "<br>"
  11. 'put "--form_val := " & form_val & "<br>"
  12. 'put "--serialized_key := " & serialized_key & "<br>"
  13. Session(serialized_key) = form_val
  14. Next
  15. End Sub
  16. 'given a form name, returns a dict with the form's stored values
  17. Public Function DeserializeForm(form_name)
  18. dim dict : set dict = Nothing
  19. dim serialized_key, serialized_val, form_key, form_val
  20. For Each serialized_key in Session.Contents
  21. 'put "serialized_key: " & serialized_key & "<br>"
  22. If InStr(serialized_key, "mvc.form." & form_name) > 0 then
  23. 'put "--match" & "<br>"
  24. If dict Is Nothing then
  25. set dict = Server.CreateObject("Scripting.Dictionary")
  26. 'put "dict created<br>"
  27. End If
  28. form_val = Session(serialized_key)
  29. form_key = Replace(serialized_key, "mvc.form." & form_name & ".", "")
  30. dict(form_key) = form_val
  31. 'Session.Contents.Remove serialized_key
  32. 'put "--serialized_val: " & serialized_val & "<br>"
  33. 'put "--form_val: " & form_val & "<br>"
  34. End If
  35. Next
  36. set DeserializeForm = dict
  37. End Function
  38. 'given a form name, clears the keys for that form
  39. Public Sub ClearForm(form_name)
  40. dim key
  41. For Each key in Session.Contents
  42. If InStr(key, CachedFormKeyName(form_name, key)) > 0 then
  43. Session.Contents.Remove key
  44. End If
  45. Next
  46. End Sub
  47. Private Function CachedFormKeyName(form_name, key)
  48. CachedFormKeyName = "mvc.form." & form_name & "." & key
  49. End Function
  50. End Class
  51. dim FormCache__Singleton
  52. Function FormCache()
  53. if IsEmpty(FormCache__Singleton) then
  54. set FormCache__Singleton = new FormCache_Class
  55. end if
  56. set FormCache = FormCache__Singleton
  57. End Function
  58. %>

Powered by TurnKey Linux.