Discussion:
[cgi-prototype-users] linking to non-default page
John S J Anderson
2005-06-28 12:59:33 UTC
Permalink
I'm just starting to try to wrap my head around C::P::Hidden (or vice
versa), so it's entirely possible I'm not thinking about this properly
-- but I can't figure out the Right Way to link to a non-default page.

Suppose I have two "pages": Welcome and Login. (A "page" is a
combination of a .pm and a .tt; there's only one actual CGI.) I have

sub config_default_page { "Welcome" }

in the base My::App.pm.

In Welcome.tt, I want to have an <a> element where the href attribute
takes me to the Login page. It seems like I have two options:

1) use an onClick attribute to manipulate the hidden _state field to
change its value to 'Login'
2) encode '?_state=Login' into the URL in the href attribute (or various
other schnanigans with specifying some state in the URL -- use
'state=login' and switch on that in the respond_per_page() in the
base class, for example)

Is that pretty much accurate or is there some slickness I'm missing?

thanks,
john.
--
The test of a first-rate intelligence is the ability to hold two
opposed ideas in mind at the same time and still retain the ability to
function. One should, for example, be able to see that things are
hopeless and yet be determined to make them otherwise. - F. Scott Fitzgerald
Randal L. Schwartz
2005-06-28 13:16:47 UTC
Permalink
john> 2) encode '?_state=Login' into the URL in the href attribute (or various
john> other schnanigans with specifying some state in the URL -- use
john> 'state=login' and switch on that in the respond_per_page() in the
john> base class, for example)

I've used this, and recommend this. In the fictional
CGI::Prototype::Cookbook, I have this:

USE selfcgiurl = url(self.CGI.url({ path => 1 }));
BLOCK link;
# [ state = "new state" ] (defaults to current state)
# [ other = { ... } ] (additional URL params)
csp = self.config_state_param;
DEFAULT state = self.param(csp);
DEFAULT other = {};
other.$csp = state;
selfcgiurl(other);
END;

Then I can say:

[% WRAPPER link state = "Login" %]Login![% END %]

Note that this requires config_state_param to not begin with an
underscore or dot, thanks to some odd interactions with TT's
restrictions.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Randal L. Schwartz
2005-06-28 13:23:29 UTC
Permalink
Randal> Then I can say:

Randal> [% WRAPPER link state = "Login" %]Login![% END %]

No, that's not right. I have to do something with a href =.

Not sure how I was using that here. :)


Randal> -------------------------------------------------------
Randal> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
Randal> from IBM. Find simple to follow Roadmaps, straightforward articles,
Randal> informative Webcasts and more! Get everything you need to get up to
Randal> speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
Randal> _______________________________________________
Randal> cgi-prototype-users mailing list
Randal> cgi-prototype-***@lists.sourceforge.net
Randal> https://lists.sourceforge.net/lists/listinfo/cgi-prototype-users
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<***@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Andrew Gianni
2005-06-28 13:50:59 UTC
Permalink
Generally, here's how I've dealt with it:

Make your link on the welcome page something along the lines of:

<a href="_state=login'>Log In</a>

In login.pm you'll need to cover both the case where they're coming to the
login page via a link (hint: make sure the username and password params
aren't set or make sure that only _state is set), and the case where the
username and password are set and should be processed.

Andrew
Post by John S J Anderson
I'm just starting to try to wrap my head around C::P::Hidden (or vice
versa), so it's entirely possible I'm not thinking about this properly
-- but I can't figure out the Right Way to link to a non-default page.
Suppose I have two "pages": Welcome and Login. (A "page" is a
combination of a .pm and a .tt; there's only one actual CGI.) I have
sub config_default_page { "Welcome" }
in the base My::App.pm.
In Welcome.tt, I want to have an <a> element where the href attribute
1) use an onClick attribute to manipulate the hidden _state field to
change its value to 'Login'
2) encode '?_state=Login' into the URL in the href attribute (or various
other schnanigans with specifying some state in the URL -- use
'state=login' and switch on that in the respond_per_page() in the
base class, for example)
Is that pretty much accurate or is there some slickness I'm missing?
thanks,
john.
--
Andrew Gianni
Administrative Computing Services
State University of New York at Buffalo
215 Millard Fillmore Academic Complex
Amherst, NY 14261
(716) 645-3587x7124
Loading...