Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Include Question

Status
Not open for further replies.

vego

Programmer
Jun 26, 2004
47
0
0
US
I posted this same question in the Perl forum, but now that I think about it, maybe it can be solved here.

What's the proper way to include a cgi script into an HTML (using an include) page? I know I can simply insert <!--#include virtual="/cgi-bin/script.cgi" --> into the correct div in the page, but then how does one control the output of the script to be contained within that div. I'm using an iframe to do the include at the moment, and that works fine (except I get iframe scrollbars). How would I go about this including it only into a div... not an iframe. I see it done everywhere, but can't seem to figure out exactly how it's done. Anyone?
 
Hi mate,

Using an include does not affect the formatting in any way. The include is simply that, it includes the output of one file into another. You would use the Div to control the display of the script contents, or do it within the script itself.

Hope this helps

Wullie

Fresh Look - Quality Coldfusion Hosting

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
I know I can simply insert <!--#include virtual="/cgi-bin/script.cgi" --> into the correct div in the page, but then how does one control the output of the script to be contained within that div

You've answered your own question really, you put the #include directive into the relevant part of the page. Let me see if I can spell it out though...

Suppose your page - index.shtml - looks like this:
Code:
<html>
<head>
<title>Include Fun</title>
</head>
<body>
<p>
<!--#include virtual="/cgi-bin/script.cgi" -->
</p>
</body>
</html>

You'd make script.cgi look like this:
Code:
#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "Hello World!\n";

What visitors will see when they visit your page (and view source) is this:
Code:
<html>
<head>
<title>Include Fun</title>
</head>
<body>
<p>
Hello World!
</p>
</body>
</html>

Does that help?

-- Chris Hunt
 
Yes, I know all about what you're saying. The problem lies in the execution of the script once it's loaded into the div.

Example:

I load a div with a script using an include... no prob. Now, that script is a form dynamically generated by the script with an action set to do some server-side task and display it as a new page. Doesn't work as it should. It replaces the whole page with the output of the script. At least using an iframe, I got the control I wanted, but didn't want the scrollbars. Does this make it more clear?
 
It replaces the whole page with the output of the script.
Which page are you talking about here?

Do you mean that the page into which your dynamic form is included is disappearing? Frankly, I don't see how this can be possible, but maybe some servers might lose the portion of the page after the include script if the script ends in an error?

Alternatively, do you mean that on pressing the [Submit] button of the form you want its output displayed in a new window but it actually overwrites the one containing the form. To get a new window you need to include a [tt]target="_blank"[/tt] attribute in the [tt]<form>[/tt] tag generated by your include script.

-- Chris Hunt
 
First, you're executing the script fine, you could also use exec cgi but the result is the same.

I think I see the problem, rather that displaying the result of the script you are actually including the form which them executes and presents the results in a new page. Is this correct?

I guess what you need to do is modify the script so that only the result will be sent to the browser rather than the form. Other option is to stick with the iframe as when the script executes the results will still be in an iframe.

Iframe != SSI Include



<!--#sig value=''É'' url='' -->
 
Ok, Thanx, guys for the input, but I guess the only way is the iframe.

One last shot, I'll try to further explain:
I have a page in which I include a Perl script like this into the content div. <!--#include virtual="script.pl" --> That works just fine. The problem is the script is a dynamically generated form that when the submit button is executed, I need the output of the script to remain in that div...not replace the window with the output. The script works just fine using an iframe, but my goal was to do it as I mentioned above. In essence, I would need to somehow define in my script for the output to open in the content div, (much like one defines the output to target the iframe) but I can't seem to find that solution.
 
<div>s are not the same as <iframe>s. A <div> is just like any other block-level element - a <p> or a <blockquote> or a <table> - it marks off a section of an HTML document. Unlike those other elements, <div> has no default appearance or behaviour - you add that in yourself using CSS.

<iframe>s are different beasties. They define an area on a page and tell the browser "put this other HTML document in there". A link or a form in the iframed document (i.e. the document inside the <iframe>) will only affect the contents of the <iframe>, not its parent document.

When you submit a form, the resulting page is sent back to the place from which it was requested. If that was a document inside an <iframe>, the whole content of the <frame> will be replaced. If it was a normal document, the whole document will be replaced. There's no way to selectively update bits of a sending page.

If you think you've "see[n] it done everywhere", you're wrong. What's happening is the form's sending back a results page that looks like your sending page, with the relevant bit changed. Or maybe using an <iframe>.


-- Chris Hunt
 
Thanx, Chris...
I have just recently learned that the technique I am looking for uses the HTML::Mason module in Perl, so I guess I'll look into that method. Temporarily, though, I think I can add the "extra" data to the output of my script to simulate replacing the "whole" page as opposed to what I have now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top