0

Is there a way to determine if a form with id/name X is submitted without checking the Request.Form object?

The reason I am asking is because I have some common code (executes on every pageload) which checks if the login/logout form has been submitted, and this conflicts with some file upload pages (because it needs to use Request.binaryRead - which can't be used after using Request.Form).

How does one typically handle this?

Same Question here, but there are no good answers. Access form post Data without request.Form

Community
  • 1
  • 1
GWR
  • 1,878
  • 4
  • 26
  • 44

1 Answers1

4

The enctype attribute an HTML Form element affects request's Content-Type header which allows you to determine what kind of form is submitted.
So, you simply need to check HTTP_CONTENT_TYPE server variable.

If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
    'a POST request was made

    If InStr(1, Request.ServerVariables("HTTP_CONTENT_TYPE"), "multipart", vbTextCompare) = 1 Then
        'Content-Type header starts with multipart
        'possible file upload form (<form method=post enctype=multipart/form-data ...)
        'using Request.BinaryRead is OK
    Else
        'ordinary HTML form
        'using Request.Form is OK
    End If
End If
Kul-Tigin
  • 16,728
  • 1
  • 35
  • 64