Nice. Giving the images the same name, and associating a value is probably the most "elegant" way.

As an alternative to a series of if...elsif...else statements, you could also use a hash of acceptable action names, paired with a sub, e.g.:

my %actions = ( invite => sub { ... }, view => sub { ... }, leave => sub { ... }, ); my $action = $cgi->param('action'); $actions{$action}->() if exists $actions{$action};

Update:

...except that from an HTML perspective, I don't think that using the same name for the input/image elements will work. According to the the HTML 4 standard,

When a pointing device is used to click on the image, the form is submitted and the click coordinates passed to the server. The x value is measured in pixels from the left of the image, and the y value in pixels from the top of the image. The submitted data includes name.x=x-value and name.y=y-value where "name" is the value of the name attribute, and x-value and y-value are the x and y coordinate values, respectively.

So, it looks like in the CGI script, you'd have to get the coordinates; you can't assign a value to that input/image element, since it acts like a submit button. So, we're probably again reduced to haveing to use separate names, and detecting the different names, or alternatively, knowing the coordinates that will be returned and detecting those.

Or, like I mentioned before (and like wildooUK mentions below), use JavaScript. :-)


In reply to Re: Re: CGI question: elegant way to have three form image buttons doing different things? by t'mo
in thread 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.