Dear Monks,

I'm wondering if someone could help me understand why the following doesn’t work.

I have a CGI script that displays different contents depending on whether or not the “Submit” button has been clicked. The CGI script works fine by itself, but when I attempt to include it in a .shtml file by way of an SSI on Apache 2.2.6, it doesn’t work. After clicking the submit button, the original form just redisplays as if the button had never been clicked. I get the same results with both of the following:

<!--#include virtual="/cgi-bin/choose_color.cgi"--> <!--#exec cgi="/cgi-bin/choose_color.cgi"-->

On the other hand, simple SSIs (such as to display the date, or a visitor counter CGI script) work fine. I have also tried using <FRAME> tags in a separate .html file to put the CGI in it’s own frame…..this works as long as it’s the only frame. As soon as I add another, the CGI form no longer displays at all.

I wanted to do this because the HTML file already exists with all the proper formatting, and I thought I could just rename it to .shtml and include the CGI. So, I’m wondering the following:

1) Are the results I’m seeing with the .shtml files expected? If so, could you help me understand why?

2) What would be a better approach for what I want to do?

My test case is below:

choose_color.shtml
<html> <head> <title>Choose Color</title> </head> <body> <p><!--#exec cgi="/cgi-bin/choose_color.cgi"--></p> </body> </html>
choose_color.cgi:
#!c:/perl/bin/perl.exe use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; use warnings; print header, start_html, h3("Choose Color"), hr; my $query = CGI->new(); if ($query->param('Submit')) { # If user has chosen a favorite color print p("You chose <b>", $query->param('color'), "</b>.\n"); } else { # User hasn't yet chosen a favorite color print p("Choose your favorite color:\n"); print start_form; print p($query->popup_menu(-name=>'color', -values=>[qw(blue green + red gold yellow)]), $query->submit("Submit")); print end_form; } print end_html;

Thank you,
memnoch


In reply to CGI form doesn't work by way of SSI by memnoch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.