Popcorn Dave has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I've come across an interesting problem with Firefox and CGI scripts.

I've got a script I'm working on that has forms on a couple of pages. No problems with that - Firefox renders the HTML just fine as I would expect it to. The problem comes in when I've got a graphic with a link attached to it Firefox does a lookup and doesn't reference itself. IE will load the next page - assuming that the requisite information has been filled in.

When I have the hyperlink outside the form, both IE and Firefox are showing the submit button's link as being the link on the graphic above.

My questions are:

  1. Why would a link outside the form affect the submit button?
  2. Why is the CGI module showing the link above and not a blank for my submit button?
  3. Is there something that I need to do differently to in calling the submit? Currently I'm doing
    print $query->submit(-name => "Go to Step 3"),
    to submit the form.

The odd thing is that Firefox will display the second page when I remove the hyperlink outside the form. Any light anybody can shed on this would be greatly appreciated.

Update: Thanks to ikegami I found a typo in my URL which solved my problem partially. However the URL is still going wrong with the submit button in Firefox.

Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.

Replies are listed 'Best First'.
Re: CGI.pm form buttons and Firefox
by ikegami (Patriarch) on Apr 18, 2005 at 20:29 UTC
    Could you show us a minimal HTML doc that exhibits this problem?
      Here's the pared down code that CGI generated which works in IE but not Firefox. Clicking on the submit button invokes the URL http://wrights/index2.html, not the cgi script itself.
      <?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-U +S"><head><title>Wright Popcorn &amp; Nut Company - Web Store</title> <style type="text/css"> <!--/* <![CDATA[ */ img {border:0 none;} a {text-decorati +on:none} /* ]]> */--> </style> </head><body bgcolor="#FFA1A6"><div style="position:absolute; left:0px +; top:150px;"> <img border="0" src="menuborder.gif" /> </div> <div style="position:absolute; left:25px; top:150px;"> <a href="http://wrights/index2.html" /> ## problem link <img border="0" src="home.gif" /> </div> <table border="0" cellpading="5"> <tr> <td><img border="0" src="cornerlogo.gif" /></td> <td width="20%"></td> <td><img border="0" src="wrightlogo.gif" /></td> </tr> </table> <br /> <br /> <br /> <form method="post" action="/testbasket.cgi" enctype="application/x-ww +w-form-urlencoded"> <input type="hidden" name="page" value="1" /><table border="0" cellsp +acing="0" cellpadding="0"> <tr> <td rowspan="2" valign="top"><img src="order1.jpg" /></td> <td><table border="0" cellpadding="5" cellspacing="5"> <tr> <td colspan="5"><center> <h1> Web Store </h1> </center></td> </tr> </table></td> </tr> </table> <input type="submit" name="Go to Step 2" value="Go to Step 2" /><div>< +/div></form></body></html>
      Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.
Re: CGI.pm form buttons and Firefox
by chas (Priest) on Apr 18, 2005 at 21:17 UTC
    One problem (perhaps the main one) is that the link <a href="http://wrights/index2.html" /> isn't terminated with </a> See if that fixes things.
    chas
      That's a good thought, but the HTML I posted is what CGI.pm is generating. I'm not sure how to tell it to make a closing tag since I'm calling it like this:

      $query->a({-href => 'http://wrights/index2.html'}), $query->img({-src => 'home.gif', -border => 0}));

      My understanding was that CGI.pm took care of the closing tags and that was one ( of many )reasons to use it rather than printing tons of html statements.

      Useless trivia: In the 2004 Las Vegas phone book there are approximately 28 pages of ads for massage, but almost 200 for lawyers.
        Is that cut and pasted from the original source?

        If it is, the closing parenthesis noted below needs to be removed. The img tag is printed after the anchor tag is closed - it needs to be inside the anchor.

        # ============ remove this paren ================v $query->a({-href => 'http://wrights/index2.html'}), $query->img({-src => 'home.gif', -border => 0}));
        BTW, with the paren removed it (CGI.pm v3.04, perl 5.8.4) prints: <a href="http://wrights/index2.html"><img border="0" src="home.gif" /></a>, which should do what you want.
        Yes, I see what you mean. It seems to be because you have no text included for the link. Try
        a({-href => 'http://wrights/index2.html'},"Link")
        That seems to work better. However, one would think it would work without the text. I've had trouble with the HTML producing functions in CGI.pm myself for various reasons.
        chas
        (I checked with the non OO setup, but that shouldn't make a difference.)
        (Update: Oh, sorry, I guess I didn't realize that the image was part of the link (because the closing parenthesis was there)...bmann seems to have fixed things.)