Thanks Jesse,
Your solution is basically what I came up with also. I added an alternative
run-mode parameter that the routine could fall back on if it didn't find any
parameters with a trailing x or y preceded by a period.
> sub select_runmode {
> my $self = shift;
> my @params= $self->param(); # Get all form parameters
> my $alt_runmode = $self->param('alternative_runmode');
>
> foreach my $param (@params) {
> if ($param =~ /(\S+)\.(x|y)/) {
> return $1 if (defined($1));
> }
> }
>
> #Didn't find an image submit?
> return $alt_runmode;
> }
I've got nothing against javascript, but it's not something you can rely-on
100% of the time. It's also more code to maintain (however small.)
Nice to know I'm starting to think like the 'Big Boys' of Perl.
Anyhoo, thanks for the suggestion (confirmation), and thanks for some great
modules too (HTML::Template changed my life !)
-jerry
On 3/18/02 9:09 AM, "Jesse Erlbaum" <[EMAIL PROTECTED]> wrote:
> Hey All --
>
> Regarding image buttons, I'm an advocate of using light-weight Javascript
> for this purpose:
>
> <a href="javascript:submit_rm_one()"><img src="rm_one.gif"></a>
>
> This is, to me, the most simple, reliable way of having multiple image
> buttons to submit from a single form to multiple run-modes.
>
>
>> No, unfortunately you can't. When an image submit button is
>> used the 'value'
>> attribute is not passed with the form parameters. What you
>> get out of the
>> image button is a 'rm.x=29' and 'rm.y=47', the numbers being
>> the pixels
>> where the user clicked from left and top of the image.
>
> If you are adverse to Javascript (and I know a couple of you are!), there is
> a way you could use these "X/Y" coordinate behaviors. It's a bit of a Rube
> Goldberg machine. I would never do it, unless there was an absolute reason
> never to use Javascript -- but it ought to work.
>
> One solution is to make use of the ability built in to CGI::Application to
> supply a subref to mode_param(). Your subref would point to a function
> which looks at the image-submit form data and translates it into the name of
> a run-mode.
>
> For example, this HTML:
>
> <form>
> <input type="image" name="mode1" src="/images/mode1.gif">
> <input type="image" name="mode2" src="/images/mode2.gif">
> </form>
>
>
> ...Would be handled by the following CGI-App code:
>
> sub setup {
> my $self = shift;
>
> $self->mode_param(\&figure_out_rm_from_image_submit);
>
> $self->run_modes(
> # ...Define run-modes as you usually would
> );
> }
>
> sub figure_out_rm_from_image_submit {
> my $self = shift;
>
> my $q = $self->query();
> my @params = $q->param();
> foreach my $p (@params) {
> $p =~ /^(\S+)\.x$/;
> return $1 if (defined($1));
> }
> }
>
>
> (Note: I've not even remotely tested this code!)
>
>
> This would allow you to have all your buttons as image-submits. Naturally,
> you'd have to add additional code to support anything else, but this would
> get you in the ball-park.
>
>
> TTYL,
>
> -Jesse-
+---------------------------+
| Jerry Hamlet |
| Web Designer/Programmer |
| www.hamletzone.com |
| [EMAIL PROTECTED] |
+---------------------------+
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]