Subject: | CGI::button and CGI::start_button unfortunate inconsistency |
Hello.
(Note: technical environment information is probably irrelevant, but included at the end nontheless)
I have found an unfortunate inconsistency between the "CGI::button()" method and the (auto-generated) "CGI::start/end_button()" methods in CGI.pm, when trying to achieve this:
<button type="submit" name="action">label</button>
(cf. http://www.w3.org/TR/html401/interact/forms.html#edef-BUTTON )
The only way to do this with the CGI module is to use the "auto generated" "start_button" and "end_button" methods, as both "CGI::submit" and "CGI::button" generate an <input...> item. knowing that "CGI::input({-type=>'button'})" can be used to achieve the same result as "CGI::button()", it would seem logical to me to modify "CGI:button()" to eliminate the inconsistency and at the same time add a feature to CGI.pm.
In other words, because "
use CGI qw/:any/ ;
my $cgi = new CGI ;
print $cgi->start_button({ -name => 'action', -value => 'newInfo' }) ;
print 'Create new information' ;
print $cgi->end_button() ;
" generates "
<button name="action" value="newInfo">Create new information</button>
", I would expect "
use CGI ;
my $cgi = new CGI ;
print $cgi->button(
{ -name => 'action', -value => 'newInfo' },
'Create new information'
) ;
" to do exactly the same thing.
This is in no way more difficult than the way "table", "td", and such tags are handled.
I understand, though, that modifying the semantics of the "button" method would break many scripts. So I suggest that "start_button" and "end_button" be modified to match the current "button" method (consistency), and that a new method name be chosen to generate <button></button> HTML tags (completeness).
WHY do I request this / HOW did I find the issue:
I have a nice CGI script here, written using the CGI module without a trace of hard coded HTML code in it (which is The Best Way(tm) in the context I'm working here - doing so reduced the size of the original script by 40% while improving it maintenability). My problem is that I would like to create submit buttons for a form using three different values for -1- the button name, -2- the button value and -3- the button label. The reason is simple: I have several submit buttons, that I would like to be all mapped to the "action" parameter of my script. I would also like the different actions to be mapped to "simple to parse" values ("record", "delete", "newItem", and the like). And last but not least I would like to have informative labels, with spaces in them, etc. As you can see, nothing extraordinary.
The "CGI::submit" method generates an [input type="submit"] item for which the label can only be the content of the "value" attribute (or the "name" if there is no "value").
The "CGI::button" method generates an [input type="button"] item which suffers from the same issue (and from being designed for use with javascript, which is not an option here).
Technical context (irrelevant):
- Module: CGI.pm versions 2.56 (on perl 5.6.0) and 3.07 (on perl 5.8.6)
- O.S.: Red Hat Linux 7.2
- $(uname -a): Linux ### 2.2.16-22 #1 Tue Aug 22 16:49:06 EDT 2000 i686 unknown
- Hardware: old HP server (can't remember the model)
Best regards,
Xavier Lagraula