Consolidated ASP Classic MVC framework from best components
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

79 lignes
2.7KB

  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, prefix, keysToRemove(), idx
  41. prefix = "mvc.form." & form_name & "."
  42. ReDim keysToRemove(-1)
  43. ' First collect the keys to remove
  44. For Each key In Session.Contents
  45. If Left(CStr(key), Len(prefix)) = prefix Then
  46. ReDim Preserve keysToRemove(UBound(keysToRemove) + 1)
  47. keysToRemove(UBound(keysToRemove)) = key
  48. End If
  49. Next
  50. ' Then remove them
  51. For idx = 0 To UBound(keysToRemove)
  52. Session.Contents.Remove keysToRemove(idx)
  53. Next
  54. End Sub
  55. Private Function CachedFormKeyName(form_name, key)
  56. CachedFormKeyName = "mvc.form." & form_name & "." & key
  57. End Function
  58. End Class
  59. dim FormCache__Singleton
  60. Function FormCache()
  61. if IsEmpty(FormCache__Singleton) then
  62. set FormCache__Singleton = new FormCache_Class
  63. end if
  64. set FormCache = FormCache__Singleton
  65. End Function
  66. %>

Powered by TurnKey Linux.