Subject: | Trivial Problem with end_form |
Running perl 5.6.1 under FreeBSD 4.7-RELEASE-p28 #40, using CGI.pm versions 3.08+, I have encountered what I believe is a trivial problem with end_form.
In particular, when validating a web page using the HTML Tidy Validator extension for Firefox (http://users.skynet.be/mgueury/mozilla/), if $self->get_fields is empty, the endform method generates "<div></div></form>" which the validator warns about with "Warning: trimming empty <div>" (did I mention that this is a trivial problem?).
If the ending code in endform is changed from
return wantarray ? ("<div>",$self->get_fields,"</div>","</form>") :
"<div>".$self->get_fields ."</div>\n</form>";
to something like
return wantarray ? ((0 == length ($self->get_fields))
? ("</form>")
: ("<div>",$self->get_fields,"</div>","</form>"))
: ((0 == length ($self->get_fields))
? "\n</form>"
: "<div>".$self->get_fields ."</div>\n</form>");
or even this (if my Perl is up to snuff)
$nl = wantarray ? '' : "\n";
@ef = (0 == length ($self->get_fields))
? ("$nl</form>")
: ("<div>",$self->get_fields,"</div>","$nl</form>");
return wantarray ? @ef : join '', @ef;
then the HTML Tidy validator is happy, and this trivial problem disappears.