CGI.pm Button Generation

F

FeelLikeANut

I need the CGI module to be able to generate the following HTML:

<button name="overwrite" value="yes" type="submit">Overwrite</button>
<button name="overwrite" value="no" type="submit">Cancel</button>

I can't figure out how to get CGI.pm to do this. Can someone help me
find what I'm missing?
 
M

Michael Vilain

I need the CGI module to be able to generate the following HTML:

<button name="overwrite" value="yes" type="submit">Overwrite</button>
<button name="overwrite" value="no" type="submit">Cancel</button>

I can't figure out how to get CGI.pm to do this. Can someone help me
find what I'm missing?

AFAIK, <button> isn't widely used HTML and not recommended. What DTD
are you using and what version of CGI.pm are you running? I'm running
1.33, which is ancient, but only because that's what my web hosting
company is running.

In any case, when I use CGI to generate the button code:

use CGI;
$q = new CGI;
print $q->button(-name=>"overwrite",
-value=>"yes",
-type=>"submit");

This generates the following HTML:

<INPUT TYPE="button" NAME="overwrite" VALUE="yes" TYPE="submit">

The W3C spec for <button> says

"The BUTTON element defines a submit button, reset button, or push
button. Authors can also use INPUT to specify these buttons, but the
BUTTON element allows richer labels, including images and emphasis.
However, BUTTON is new in HTML 4.0 and not as widely supported as INPUT.
For compatibility with old browsers, INPUT should generally be used
instead of BUTTON."

http://www.htmlhelp.com/reference/html40/forms/button.html

If you look at the code in CGI.pm, it may not support <button> and use
<input> instead. The only way around this is to code the HTML by hand
and not use CGI.pm.
 
F

FeelLikeANut

AFAIK, <button> isn't widely used HTML and not recommended. What DTD
are you using and what version of CGI.pm are you running?

HTML 4.01 Strict and CGI.pm 3.25.
I'm running
1.33, which is ancient, but only because that's what my web hosting
company is running.

In any case, when I use CGI to generate the button code:

use CGI;
$q = new CGI;
print $q->button(-name=>"overwrite",
-value=>"yes",
-type=>"submit");

This generates the following HTML:

<INPUT TYPE="button" NAME="overwrite" VALUE="yes" TYPE="submit">

The W3C spec for <button> says

"The BUTTON element defines a submit button, reset button, or push
button. Authors can also use INPUT to specify these buttons, but the
BUTTON element allows richer labels, including images and emphasis.
However, BUTTON is new in HTML 4.0 and not as widely supported as INPUT.
For compatibility with old browsers, INPUT should generally be used
instead of BUTTON."

http://www.htmlhelp.com/reference/html40/forms/button.html

Well, to be fair, citing htmlhelp.com is not the same as citing the
W3C spec. The spec itself does not make the recommendation to use
IINPUT instead of BUTTON. Also, HTML 4 and BUTTON have been around for
more than nine years now -- more than enough time, I would think, for
browsers to support it, and in fact they have. It seems to be only
CGI.pm that is lacking in this regard.
If you look at the code in CGI.pm, it may not support <button> and use
<input> instead. The only way around this is to code the HTML by hand
and not use CGI.pm.

Yes, that is the conclusion I've come to as well, unfortunately. I
wanted to make sure I wasn't missing something. I'd have thought that
CGI.pm would have added support for BUTTON a long time ago.
 
G

Guest

I need the CGI module to be able to generate the following HTML:

<button name="overwrite" value="yes" type="submit">Overwrite</button>
<button name="overwrite" value="no" type="submit">Cancel</button>

I can't figure out how to get CGI.pm to do this. Can someone help me
find what I'm missing?

Michael Vilain's comments apply. However, if you are willing to risk
using the "-any" option to CGI.pm, you can do this:

use CGI qw(-any);

print CGI::Button({
name => 'overwrite',
value => 'yes',
type => 'submit',
},
'Overwrite'), "\n";

print CGI::Button({
name => 'overwrite',
value => 'no',
type => 'submit'},
'Cancel'), "\n";

I don't advise this however. The "-any" option will automatically create
any weird function name you can imagine, and that could create some hard
to find bugs.
 
F

FeelLikeANut

To use the same name in the same form for other inputs then "radio" is not a
good idea at all ;-)

Um ... why not? It's legit and works very conveniently.
Second ... why you want to use CGI module for this non standard html code?

Non standard code? It's been standardized for more than nine years.
In any case, I'd prefer to use CGI.pm because I'm writing a module
that returns HTML code from some of its functions. Those functions
take a CGI object reference as an argument and use that object to
generate HTML. This lets the module adapt -- without lots of extra
code -- to the different requirements of each user, such as whether to
output HTML or XHTML, and the character encoding being used.
 
A

anno4000

On Feb 7, 3:32 am, (e-mail address removed) wrote:


(snipped)



What about extending CGI?

Right. That's the spirit!
Something like:

[good-looking code snipped]
I'm sure the above is insufficiently tested but
it's a start.

Once it *is* sufficiently tested, submit it as a patch to CGI.pm.
That's how open-source software grows.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top