I'm attempting to make an HTML form with three different images that do three different actions. The buttons must be images, and all three buttons must be in the same form.

I made this simple script to test. Does anyone know a more elegant way to do this? I can't do three separate forms, because I need the data in the text box. Note that this is purely academic, as I am doing nothing exciting with the form data, I just thought it was an interesting problem.
#!/usr/bin/perl -Tw use CGI; use CGI::Carp qw( fatalsToBrowser ); use strict; my $cgi = CGI->new(); my $mode = $cgi->param('mode'); my $action = get_action( $cgi ); my $date = scalar localtime(); print $cgi->header(); print <<EndHTML; <html> <head><title>Test Three: ( $action : $mode )</title></head> <body> <form method="get" action="test_three.cgi"> <input type="text" name="date" value="$date"><br> <input type="image" name="invite" alt="Invite" src="invite.gif"> <br> <input type="image" name="view" alt="View Results" src="view.gif"> <br> <input type="image" name="leave" alt="Leave" src="exit.gif"> <br> <input type="hidden" name="mode" value="1"> </form> </body> </html> EndHTML sub get_action { my $cgi = shift; my $action; my @actions = qw( view invite leave ); TRY: for my $try ( @actions ) { if ( $cgi->param("$try.x") || $cgi->param("$try.y") ) { $action = $try; last TRY; } } $action; }

In reply to CGI question: elegant way to have three form image buttons doing different things? by meonkeys

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.