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

Hey,

I'm trying to figure out how to remove the extra "Content-Type: text/html; charset=ISO-8859-1 " header that is being printed out.

I have a script that calls another script that does the form validation.

This is not the exact coding, but I think its enough to show where my problem lies.
#BP_FORM.pl use strict; use CGI; my $INPUT = new CGI; if ($INPUT->param('action') eq "bp_form") { &bp_form; } sub bp_form { &bp_header; use BusinessFormValidation; my $webapp = BusinessFormValidation->new(); $webapp->run(); &bp_footer; } sub bp_header { print <<EOF; This is the header, below the header will view the extra "Content-Type +: text/html; charset=ISO-8859-1" EOF } sub bp_footer { print <<EOF; This leads me to think that the extra header is coming from calling th +e "$webapp->run();" part of the form validation script. EOF }
Basically, since the extra header prints from the bp_form routine, I'm assuming the extra header is being printed in the BusinessFormValidation.pm. The problem I'm having is I can't find the line anywhere in BusinessFormValidation.pm that prints the extra header.

However it does use certain modules that I think that's where my extra header is being printed.
#top of BusinessFormValidation.pm package BusinessFormValidation; use base CGI::Application; use CGI::Application::ValidateRM; use Data::FormValidator; use CGI; $CGI::DISABLE_UPLOADS = 0; $CGI::POST_MAX = 1_751_120; #1.67mb my $w = new CGI;

Is there anyway I can bypass this and remove the extra header?? I tried using the CGI feature unique header on top of my bp_form.pl script, but had no luck.

Thank you,

Anthony

Replies are listed 'Best First'.
Re: An extra content-type header
by fireartist (Chaplain) on Apr 22, 2004 at 13:58 UTC
    Your BusinessFormValidation module is using the CGI::Application module - I think you should check the docs for it.

    The CGI::Application instance is what is printing out the extra header, that's what it's supposed to do.

    If you're only using CGI::Application::ValidateRM for data validation, I think you should be using Data::FormValidator instead.
    If you do want to use CGI::Application, read the docs and let it do the bits it's supposed to, such as loading CGI and printing the header, etc...
Re: An extra content-type header
by sgifford (Prior) on Apr 22, 2004 at 16:03 UTC
    If you can't find what's printing or can't change what it prints, you can try to get it to print somewhere else. If it prints to the selected filehandle, just opening some other filehandle and selecting it would do the trick. For example, to discard output:
    open(NULL,"> /dev/null") or die "Couldn't open /dev/null: $!\n"; my $oldsel = select(NULL); # Do validation select($oldsel);

    Similarly, you could use IO::String to get the output into a string, where you could process it however you wanted.

    If it's printing to STDOUT instead of the selected filehandle, you'd have to re-assign the STDOUT filehandle to elsewhere:

    open(SAVE,">&STDOUT") or die "Couldn't save STDOUT: $!\n"; open(NULL,"> /dev/null") or die "Couldn't open /dev/null: $!\n"; open(STDOUT,">&NULL") or die "Couldn't dup NULL to STDOUT: $!\n"; # Do validation open(STDOUT,">&SAVE") or die "Couldn't restore STDOUT: $!\n";
Re: An extra content-type header
by bmann (Priest) on Apr 22, 2004 at 17:27 UTC
    CGI::Application creates the http headers for you. Two possible solutions
    1. don't bother creating your own header,
    2. if you really do want to create your own header, add the following to each run mode you want to create your own header (or in sub setup for all run modes):

      my $self = shift; $self->header_type('none'); #suppress CGI::App's header

    If you want to modify CGI::Application's header, look up header_props in the module's documentation.