Hello monks,

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.

Question

My main problem at the moment is to understand the differences and the usage of param params route_parameters query_parameters and body_parameters

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?

Further informations

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

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Dancer2 parameters understanding and usage by Discipulus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.