[Dancer-users] Keeping values on a form
Naveed Massjouni
naveedm9 at gmail.com
Thu Dec 16 22:28:07 CET 2010
On Thu, Dec 16, 2010 at 4:06 PM, ambs <ambs+dancer at perl-hackers.net> wrote:
> Hi
>
> This is not really a Dancer problem, but something that I am missing when
> changing from CGI to Dancer + TemplateToolkit.
>
> Basically:
> - I have a form with an array of checkboxes
> - that form gets submitted
> - some results are shown, together with the form for resubmission
>
> The question is, how do I keep the checkboxes checked (or not) accordingly
> with what the user picked before submitting it?
>
> For reference, CGI called this behavior as stiky: By default the CGI module
> implements a state-preserving behavior called "sticky" fields. The way this
> works is that if you are regenerating a form, the methods that generate the
> form field values will interrogate param() to see if similarly-named
> parameters are present in the query string. If they find a like-named
> parameter, they will use it to set their default values.
>
> Thank you
> ambs
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users
>
This may not be very secure, but this is how I achieve 'stickiness':
get '/foo' => sub {
# route code
template foo => {
params(),
other => 'stuff',
};
};
By passing params() into your template vars hash, it is evaluated in
list context, so they will get expanded into key/value pairs and they
will all get propogated to your template. Inside your template, you
will need to have something like:
<input name="bar" value="[% bar %]" />
I don't know off the top of my head how to handle check boxes. But
it's the same idea.
- Naveed Massjouni
More information about the Dancer-users
mailing list