Re: HTML forms
by davido (Cardinal) on Dec 27, 2003 at 16:34 UTC
|
Yes. It is. Just DWYM and it will work. HERE docs work fine, intermingled with output from CGI.pm.
Just be sure that the field names you use in your HERE doc are the same ones you look for via $q->param('...'). There is no difference between the output of the "CGI.pm HTML shortcuts" and the output of printing a HERE doc.
The strongest case for using the CGI.pm HTML shortcuts is that it adds some degree of compiletime syntax checking to your HTML. But frankly, I often find them awkward, and often find myself using CGI.pm only for it's input parameter handling, handling uploads, and for the header() method. YMMV.
| [reply] |
|
Hi davido,
But frankly, I often find them awkward, and often find myself using CGI.pm only for it's input parameter handling, handling uploads, and for the header() method. YMMV.
That's exactly what I'm using CGI.pm for. It kinda makes me wonder if it's because I've yet to fully learn its functionality with respect to outputting HTML. Ah, now I know I'm not alone...:)
The reasons I shun CGI.pm for its HTML capability are 1) I don't want to have to learn the additional syntax to do HTML and 2) I'm already very familiar with HTML and want to make use of that knowledge.
Lately, I discovered HTML::Template through this community and have since used it for managing content. I find it a really neat solution to marry the two skills of perl CGI and HTML.
| [reply] |
Re: HTML forms
by b10m (Vicar) on Dec 27, 2003 at 16:38 UTC
|
Why don't you just try and see wheter it works? But yes, you can print straight HTML.
#!/usr/bin/perl -w
use strict;
use CGI qw/:standard/;
my $q = new CGI;
print header, start_html;
if($q->param('name')) {
print h1("You becha this works.!"), p("You entered: ". $q->param('n
+ame'));
}
else {
print<<END
<form action="test.cgi" method="POST">
<table>
<tr>
<td><input type="text" name="name"></td>
</tr>
</table>
<input type="submit">
</form>
END
;
}
print end_html;
update: Removed <readmore> tags, for there wasn't that much more to read.
| [reply] [d/l] |
Re: HTML forms
by pg (Canon) on Dec 27, 2003 at 17:00 UTC
|
Don't be scared by those core modules. Although CGI.pm probably has more function calls than most of other core modules, and tend to scare people, it is actually nothing more than a bunch of functions, which take parameters and generate HTML format strings. Just as you are able to concatnate HTML strings returned from various CGI.pm function calls, it is quite obvious that you can mix your own HTML format string with them.
| [reply] |
Re: HTML forms
by CountZero (Bishop) on Dec 27, 2003 at 20:19 UTC
|
Yes, sure you can roll your own HTML.If you do that, you do not need the HTML functions of CGI.pm and you can replace CGI.pm by CGI::Simple (less overhead and faster).
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] |
|
I took your advice and plugged CGI::Simple::Standard into a current project and found it consistently about 1/10 to 2/10 of a second slower than standard CGI. Current versions of both modules on activestate. Changing one line changed the output from times():
#use CGI qw(Vars param header redirect);
use CGI::Simple::Standard qw(Vars param header redirect);
--
perl -MO=Deparse -e"u j t S n a t o e h r , e p l r a h k c r e"
| [reply] [d/l] |
|
| [reply] |
Re: HTML forms
by CharlesClarkson (Curate) on Dec 28, 2003 at 01:50 UTC
|
I would advise you avoid embedded mark up in your scripts if you can. I realize that some situations make this impossible, but one of the hardest things for many web designers to easily edit is perl code.
I prefer HTML::Template. YMMV. Search CPAN for templates. If you are going to share your code with others or if anyone else is involved with the design of your site, they will thank you for not embedding mark up.
HTH,
Charles
| [reply] |
Re: HTML forms
by esharris (Monk) on Dec 28, 2003 at 08:58 UTC
|
I started writing CGI scipts using straight HTML. But now I am experimenting with using CGI.pm.
I suggest buying Lincoln Stein's book. There is a methodology behind
CGI.pm that should make CGI scripts easier to build and maintain.
The thing that sold me is the sticky forms. If I want to let the user hit a submit button that does something and restores that form without resetting the fields to its default values, I can do it with less explicit code. Instead of reinventing this mechanism, I can use a common convention.
One side benefit and that the CGI functions often produces better output. Using straight HTML, I was able to introduce some javascript. Using CGI functions, I was able to do the same thing. However, the CGI functions also added code to comment out the javascript within older browsers.
Another side benefit is that the code needed to build tables is more compact when you use CGI functions.
I have some colleagues who applaud the move. Conversely, there are a few who make it sound like CGI is going to eventually bite me. We'll see. | [reply] |