[jifty-devel] Rendering an action as a real link

Edmund von der Burg evdb at ecclestoad.co.uk
Fri Mar 30 15:08:19 EDT 2007


Hello,

Using actions it is possible to create links on a page:


my $action = new_action(
    class   => 'SearchEntryList',
    moniker => 'search_entry_list'
);

form {

    foreach my $column ( foo bar baz ) {
        outs_raw( $action->hidden( $column => $args{$column}, ) );
    }

    hyperlink(
        url     => '/entry/',
        label   => $value,
        submit  => $action,
        as_link => 1,
    );
};


This creates a normal form, and then uses javascript magic to turn the
submit button into a link-look-a-like. This is all very clever but
breaks in a few circumstances:

 * occasionally the buttons flash up before the javascript runs.
 * layout sometimes goes askew when the width of the link text is
different from the button (especially when rendering in table cells)
 * not true links so you can't enclose images etc.
 * can't place these links inside forms of other actions

In my code I am finding myself creating lots of these links which
point through to a search page with lots of possible parameters. These
links are all static and nothing that the user does can affect their
action.

I'd like to be able to do something like this:

my $action = new_action(
    class   => 'SearchEntryList',
    moniker => 'search_entry_list'
);

my $url = $action->create_GET_url(
	'/entry/',
	foo => 'foo value',
	bar => 'bar value',
);

a {
	href is $url;
	outs('hello');
	img{ src is '/bang.png' };
};

This would take all the values and use them to create a URL that is
appended to the URL given. Obviously the method of the action would be
'GET' - caveat emptor for the programmer not to use these for state
changing actions etc.

The name and arguments to create_GET_url could probably be improved on.

I've used the firefox web developer plugin to switch the forms on a
page from POST to GET and they still work - so I don't think that
there is any change needed on the receiving end...

Any thoughts on this?

Cheers,
  Edmund.

-- 
In reality I'm evdb at ecclestoad.co.uk - http://ecclestoad.co.uk


More information about the jifty-devel mailing list