Home > Archive > PERL CGI Beginners > February 2006 > Extra <div> by start_form( ) ???
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Extra <div> by start_form( ) ???
|
|
| OliverPC@gmail.com 2006-02-11, 6:55 pm |
| There is an extra <div> block generated by start_form( ) function !!
Here is the perl code:
-------------------------------
#!perl
use strict;
use warnings;
use CGI qw( :standard );
use CGI::Carp qw( fatalsToBrowser );
print header(),
start_html(-title=>"test"),
start_form(),
textfield("hello"),
end_form(),
end_html();
Here is the HTML generated by the above code:
--------------------------------------------------------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
xml:lang="en-US"><head><title>test</title>
</head><body><form method="post" action="/cgi-bin/hello.pl"
enctype="application/x-www-form-urlencoded">
<input type="text" name="hello" />
<div></div></form></body></html>
See the extra <div></div> on last line !!!
Does anybody know why??
| |
| Paul Lalli 2006-02-12, 6:55 pm |
| OliverPC@gmail.com wrote:
> There is an extra <div> block generated by start_form( ) function !!
>
> Here is the perl code:
> -------------------------------
> #!perl
>
> use strict;
> use warnings;
> use CGI qw( :standard );
> use CGI::Carp qw( fatalsToBrowser );
>
> print header(),
> start_html(-title=>"test"),
> start_form(),
> textfield("hello"),
> end_form(),
> end_html();
>
>
> Here is the HTML generated by the above code:
> --------------------------------------------------------------------
> <?xml version="1.0" encoding="iso-8859-1"?>
> <!DOCTYPE html
> PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US"
> xml:lang="en-US"><head><title>test</title>
> </head><body><form method="post" action="/cgi-bin/hello.pl"
> enctype="application/x-www-form-urlencoded">
> <input type="text" name="hello" />
> <div></div></form></body></html>
>
> See the extra <div></div> on last line !!!
> Does anybody know why??
Because CGI.pm does a lot of things behind the scenes. One of them is
adding in any additional fields from the CGI query that were not in the
form itself. This is the code that implements the endform and end_form
methods:
#### Method: endform
# End a form
'endform' => <<'END_OF_FUNC',
sub endform {
my($self,@p) = self_or_default(@_);
if ( $NOSTICKY ) {
return wantarray ? ("</form>") : "\n</form>";
} else {
if (my @fields = $self->get_fields) {
return wantarray ? ("<div>",@fields,"</div>","</form>")
: "<div>".(join
'',@fields)."</div>\n</form>";
} else {
return "</form>";
}
}
}
END_OF_FUNC
Paul Lalli
| |
| OliverPC@gmail.com 2006-02-12, 9:55 pm |
| Paul Lalli wrote:
> OliverPC@gmail.com wrote:
>
> Because CGI.pm does a lot of things behind the scenes. One of them is
> adding in any additional fields from the CGI query that were not in the
> form itself. This is the code that implements the endform and end_form
> methods:
> #### Method: endform
> # End a form
> 'endform' => <<'END_OF_FUNC',
> sub endform {
> my($self,@p) = self_or_default(@_);
> if ( $NOSTICKY ) {
> return wantarray ? ("</form>") : "\n</form>";
> } else {
> if (my @fields = $self->get_fields) {
> return wantarray ? ("<div>",@fields,"</div>","</form>")
> : "<div>".(join
> '',@fields)."</div>\n</form>";
> } else {
> return "</form>";
> }
> }
> }
> END_OF_FUNC
>
I don't pretent that I understand that part of CGI.pm, so I still fail
to see the purpose or necessity of the extra <div>. I'd appreciate
if someone is nice enough to explain it a little bit.
My bottom line is that if I print plain html to start/end form in my
perl code, then there is no extra <div> to be concerned with. Say
when it is time to apply a CSS, there is this extra div in there for
a surprise.
|
|
|
|
|