Discipulus has asked for the wisdom of the Perl Monks concerning the following question:
I'm finally trying to take out some rusty from my web-fu and, after a 12+ years hyatus, i take Dancer2 and I'm experimenting with it with the precious support of 1nickt, but, in my wide ignorance, I found that Dancer2 manuals and tutorials give many things as already known and understood, which is not my case.
I have a template form.tt and I pass to it <% form_url %> to be used as action of the submitted form: <form action="<% form_url %>" method=post>
Then in my application module I have the folowing route:
any ['get', 'post'] => '/form' => sub { #var form_url => uri_for('/form'); # template 'form' => { 'title' => 'form', # 'form_url' => 'http://127.0.0.1:5000/form'# uri_for('/form') # }; # POST request if ( request->method() eq "POST" ) { debug "post method"; # when this is printed out +??? # process form input if ( query_parameters 'search_for') { # nor query_parameter +s->get('search_for') # debug "param defined"; this doe +s not work, why? "defined ".(query_parameters 'search_for'); # this even do +es not show up } # this works unless a template is called # "searching for ==>".(param 'search_for')."<==" ; template 'form' => { 'title' => 'formtest POST', 'search_for' => param 'search_for'}; } # GET request else { template 'form' => { 'title' => 'formtest GET', 'form_url' => uri_for('/form') }; } };
I just can make the above working using param that by docs seems to be discouraged. it is not just the case where query_parameters is appropriate? How make it to work?
I never found in Dancer2 docs things about parameters explained for dummies, as me. I'm trying to collect every possible combination of param usage and relative working URL examples to propose, maybe in near future, some addendum to official docs.
What I have already done (again only because of the help 1nickt gave to me) is on github where you can find the above route and a working simple AJAX implentation. If i reach some good degree i'l change this repository into something like step by step tutorial on parameters and AJAX.
Thanks for the attention
L*
PS any ideas about a better way to program with Dancer2 is welcome as welcome will be eventual fork/pr for the above github repository
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Dancer2 parameters understanding and usage
by 1nickt (Canon) on Nov 29, 2017 at 13:05 UTC | |
by Discipulus (Canon) on Nov 29, 2017 at 16:16 UTC | |
by 1nickt (Canon) on Nov 29, 2017 at 18:08 UTC |