views:

59

answers:

4

I have no problem executing a cgi file under the normal url like this:

http://www.myhost.com/mydir/cgi-bin/test.cgi

However when I tried to embedd it into HTML file (called index.html) like this:

<HTML>
   <BODY>
   <P>Here's the output from my program:
   <FORM ACTION="/var/www/mydir/cgi-bin/test.cgi" METHOD=POST>

   <!-- This doesn't work also -->
  <!-- FORM ACTION="cgi-bin/test.cgi" METHOD=POST-->

   </FORM>
   </P>
   </BODY>
</HTML>

The CGI doesn't get executed when I do:

http://www.myhost.com/mydir/index.html

The CGI file (test.cgi) simply looks like this:

#!/usr/bin/perl -wT
use CGI::Carp qw(fatalsToBrowser);
print "Test cgi!\n";

What's the right way to do it?

+2  A: 

The problem is the path you are providing in the action property of the form.

You need to change it to be a path relative to the current document. (index.html)

From your example, it looks like this would be cgi-bin/test.cgi

George Edison
how can u embedd anything into an html page by using a form?
Luis
I'm afraid I don't quite understand what you are saying.
George Edison
you cannot embedd an external resource into a page by using an html form. An html form allow you to send data to a specified resource.
Luis
A: 

Have you tried using an iframe:

<HTML>
   <BODY>
   <P>Here's the output from my program:
   <iframe src="http://www.myhost.com/mydir/cgi-bin/test.cgi" />
   </P>
   </BODY>
</HTML>
Luis
iframes are block elements and cannot appear inside p elements, they are also not defined as "EMPTY" so cannot use XML empty element syntax in an HTML compatible document.
David Dorward
iframes can also be used as inline elements and it is perfeclty legal to use the empty element syntax, I just inserted the above code in an html page inserted transitional doctype (strict does not like iframes) and fixed the case of all elements to lower case and the page validates against the w3c validator.
Luis
Whoops. Turns out iframe is in %flow. I take that back. The point about being forbidden in HTML-Compatible XHTML stands though. The validator does **not** check conformance to the HTML compatibility guidelines.
David Dorward
+2  A: 

There isn't a good way to do this in HTML. It is a job better suited for SSI using an exec or virtual directive.

David Dorward
+1  A: 

Use templates. It's bad idea to mix different code together. Even JS and CSS are separated from (X)HTML for readability and maintainability.

Cyberman