davidg has asked for the wisdom of the Perl Monks concerning the following question:

I am running perl 5.8.5 and CGI 3.05 and mod_perl 1.99 on an apache2 server. I seem to have to have my forms include the ENCTYPE="multipart/form-data" tag to work. Below is the test code.
<html> <head><title>Pay Memo</title> </head> <body> <form name="testform" method="post" action="step2.asp"> <input type="hidden" name="id" value="1234"><br> <input type="text" name="thedata"><br> <input type="submit" name="submit_button" value="Test +It"> </form> </body> </html>
Does not work, but if I put in the ENCTYPE
<html> <head><title>Pay Memo</title> </head> <body> <form name="testform" method="post" enctype="multipart/form-da +ta" action="step2.asp"> <input type="hidden" name="id" value="1234"><br> <input type="text" name="thedata"><br> <input type="submit" name="submit_button" value="Test +It"> </form> </body> </html>
it does work. The reading program is this:
<% use strict; use CGI; my $q = new CGI; my $data = $q->param('thedata'); %><html> <head><title>Test Script</title> <meta http-equiv="Content-Type" content="text/html; charset=is +o-8859-1"> </head> <body> Got:<%=$data%> </body> </html>
The first example code works fine under mod_perl 1. Any help as to why the ENCTYPE is required now, under mod_perl2, but not under mod_perl 1 would be appreciated. Thanks

Replies are listed 'Best First'.
Re: enctype required??
by chas (Priest) on Apr 02, 2005 at 21:23 UTC
    Take a look at 442565 and especially the comments by merlyn. (It seems to be a CGI.pm issue.)
    chas
      Thanks, but 442565 seems to be referring to HTML code generated by CGI.

      In my case, the HTML code is a static web page, coded by the WEB front end people.

      Does the new CGI only read multipart/form-data forms?

      If so, that means that I would need to have all the front end web pages that have forms changed to add the ENCTYPE tag. Not that that would cause a problem, it's just a lot of work.

        Yes, that occurred to me, but I thought maybe the fact that there is a change in CGI.pm involving enctype might be related to your problem. merlyn indicated that "the latest CGI.pm uses multipart/form-data for both start_form and start_multipart_form" so it seemed possible that it might ignore starts omitting that. Unfortunately I don't have the latest version to experiment with. Sorry,
        chas
Re: enctype required??
by ikegami (Patriarch) on Apr 02, 2005 at 22:58 UTC

    After looking at the source of the latest CGI (3.07), it looks like
    1) CGI understands POST data of type application/x-www-form-urlencoded, and
    2) CGI treats POST data as application/x-www-form-urlencoded if no Content-Type is specified by the browser.

    Can you confirm your browser is omitting the Content-Type header, or that it's set to application/x-www-form-urlencoded? What happens if you set the enctype to application/x-www-form-urlencoded?

    The issue in 442565 concerns generating forms using CGI and doesn't bear on this problem as far as I saw looking at the source.

      Thanks, I just tried it with application/x-www-form-urlencoded It still behaves the same and does not send the data to the back end.

      I am running IE6 which should send the default.

      I tried looking for CGI errors and saving the CGI to a file using the $q->save(FILEHANDLE). Nothing gave me any hints.

Re: enctype required??
by Errto (Vicar) on Apr 03, 2005 at 00:25 UTC

    Based on the code snippet it looks like you might be using Apache::ASP. It's probably not a good idea to use CGI with Apache::ASP together, since you can already get at all the form values through the $Request object.

    Update: The Apache::ASP docs say this isn't true, but I wonder how that works with the recent changes in CGI.pm

      You are correct in that I am using Apache::ASP.

      If I use $Request->Form('thedata'); to get the data it works.

      The problem is that I have lots of older code that uses the CGI that was changed into ASP code. The CGI should work in the ASP model.

      I guess the decision is which would take more time, changing the forms or changing the code....

        What happens if you add
        <%=$Request->ServerVariables(CONTENT_TYPE) %>
        in your page somewhere (using the first version of your form)?