Re: embedding a CGI script in a HTML page?

2008-12-16 Thread Adam Jimerson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Greg Jetter wrote:
 On Monday 15 December 2008 3:50:24 am Adam Jimerson wrote:
 Dermot Paikkos wrote:
 -Original Message-

 http://www.template-toolkit.org/

 Mike
 Looking at the website and the documentation, still reading through
 it,

 I'm still not sure how to mix this with my CGI scripts to make them
 look
 like the rest of the site even though Konqueror supports the object
 tag, which I would think would be the last browser to support it.  It
 may just be that I'm new to CGI so I'm having to take what I am
 learning
 and throw it out the window?
 I am not sure TT is what you want.

 If you want to run perl code from within a html tags that's not possible
 as far as I know. You could use Greg's suggestion of
 http://perl.apache.org/embperl/ or use AJAX to call your perl cgi
 scripts. But if you insist that you want to put you code in the page
 then you really want ?php

 Dp.
 I'm not trying to put perl code into the page, they way I have it now is
 I have the page generated by my CGI script inside another page that is
 using my CSS.  I've tried to have my CGI script directly handle my CSS
 but it didn't work due to its limited support for CSS.  So now I'm
 trying to find a better way to make my CGI script look like the rest of
 my site, I'm guessing this is what Template Toolkit if I can figure out
 how to do it, or if my solution is the best.
 
 if you  decide to go with a template system  , a good  simple one I use quite 
  
 a lot is the module HTML::Template . this allows you to have separate  html 
 template pages  with place holder tags that your CGI script  would process 
 and then  output to the  calling browser. You could then  just take  your 
 regular html page with your css stuff  applied and  replace  those bits that  
 have to  have a calculation or other function  with  a template var.
 
 you then can maintain the look  of your static pages with your dynamically 
 generated pages .
 
 
 Greg
 

Correct me if I am wrong but these template systems seem to only handle
output from the CGI script, which would be nice if my scripts only
handled output but they also need user input.
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAklHALEACgkQRMKiLy/EUZTeSwCfU+LlVieDGdHCRKUL+ctSGDF7
0K4AoKwU12fat1aYvympNaDk+T4PkmK0
=g0pf
-END PGP SIGNATURE-

-- 
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: embedding a CGI script in a HTML page?

2008-12-16 Thread David Dorward

Adam Jimerson wrote:

Correct me if I am wrong but these template systems seem to only handle
output from the CGI script, which would be nice if my scripts only
handled output but they also need user input

1. Browser sends input data to server

2. Server sends input data to program using CGI interface

3. Program does something (possibly with the data) and generates output data

4. Program passes output data to template

5. Template places output data into some HTML (or whatever)

6. Template passes HTML combined with output data to the program

7. Program outputs HTML combined with output data to server using the 
CGI interface


8. Server sends output HTML back to the browser

Templates are used because it is easier to edit HTML in a template then 
it is to edit Perl that generates HTML.


--
David Dorward



--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re: embedding a CGI script in a HTML page?

2008-12-16 Thread David Dorward

Adam Jimerson wrote:

No I am letting CGI.pm generate the HTML for me, I figured that it would
be the easiest way to do it.
  
Most people find that templates are simpler for most purposes (since 
they can then just write HTML and say Insert data here rather then 
describing every element in Perl).



- From what I see in the tutorial,
http://template-toolkit.org/docs/tutorial/Web.html#section_Dynamic_Content_Generation_Via_CGI_Script,
the Templete Toolkit only outputs information from the script, but I
need it to handle input as well
You use Perl to handle the input. TT is just for making it easy to write 
the output.


I've just remembered this simpler example:
http://github.com/dorward/simple-ajax-demo/tree/master

The script itself is at 
http://github.com/dorward/simple-ajax-demo/tree/master/webroot/demo.pl


Line 32 gets user input, in exactly the same way that CGI.pm would do 
(I'm using CGI::Fast for this, which is similar).


Line 33 uses that input to change what request gets sent to the database 
on ...


Line 42 (which) gets a list of messages from the database (much like a 
guestbook would).


Line 49 wraps it up in a hash.

Ignore lines 51 to 56, these output JSON instead of HTML.

Line 59 gives that hash to a template.

http://github.com/dorward/simple-ajax-demo/tree/master/templates/html.tt 
is that template.


Lines 15 to 21 of that template loop over the data and output HTML.

The rest of the template is plain, simple HTML which is easy to edit 
(and line 6 pulls a stylesheet in).


--
David Dorward
http://dorward.me.uk/

--
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/




Re:[SOLVED] embedding a CGI script in a HTML page?

2008-12-16 Thread Adam Jimerson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Mike Williams wrote:
 I have tried that and when I tried to call up a div object, in my css
 (is attached) called leftcolumn, instead of getting a navy blue column
 on the left side of the page it is just white.

 
 Did you  perhaps  use  'div class='leftcolumn'   ?
 
 That will not work with your stylesheet.
 
 div id='leftcolumn'  *will* work
 
 Here is a little cgi program that uses CGI.pm and your style sheet to print
 a some stuff in a blue column on the left side of the screen:
 #!/usr/bin/perl
 use warnings;
 use strict;
 use CGI;
 
 my $q = CGI-new();
 print $q-header(), $q-start_html(-title=list msg test,
 -style={'src'='/css/se.css'}),
   'div id=leftcolumn';
 for (my $i = 1; $i  26; $i++) {
 print $q-br(blue column line $i);
 }
 print '/div', $q-end_html();
 
 

I have tried div id but they way I tried it was different, this is how I
tried it

print div id=leftcolumn;
print Some information;
print /div;

I guess that I was doing something wrong because it is working now thank
you for the help


 - From what I see in the tutorial,

 http://template-toolkit.org/docs/tutorial/Web.html#section_Dynamic_Content_Generation_Via_CGI_Script
 ,
 the Templete Toolkit only outputs information from the script, but I
 need it to handle input as well, my script I am working on is a
 guestbook so it needs to get the name of the guest and a message then
 output it, as well as save it to a log for later use by the script.
 Everything works but the plain white background is ugly and doesn't
 match the rest of my site which is why I started this thread.

 
 You seem to be under the mistaken impression that you cannot get input using
 CGI.pm or Template::Toolkit.
 
 That is incorrect, either of those tools allow you to generate forms that
 can be used to get input from the user.
 
 If you look at perldoc CGI the very first screen contains an example of how
 to generate a form.
 

I know how to generate forms with CGI which is where I have been putting
my forms, but I didn't think that Template::toolkit could generate a
form and pass the information off to the script for processing.

 Hope this helps,
 
 Mike
 

-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.9 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iEYEARECAAYFAklIC5sACgkQRMKiLy/EUZTjqgCgnQj5UdmboFiqq0VkmY4i6VYD
m6gAn2kcHUDfKNtSk89NSqlU1w/ugrOu
=WL/f
-END PGP SIGNATURE-

-- 
To unsubscribe, e-mail: beginners-cgi-unsubscr...@perl.org
For additional commands, e-mail: beginners-cgi-h...@perl.org
http://learn.perl.org/