<div dir="ltr"><div><div><div>Hi WK,<br><br></div>Thanks again for the reply. When I try it your way:<br><br> redirect "/sport_add/$id";<br><br></div>Dancer attempts to serve up the page /sport_add/105 (105 being an the value of $ID) and of course gets an error. Not sure what I am doing wrong. Also, are you saying that hook before makes the <span class="im">var S_id global? I have tried invoking it briefly in other routes and it did not seem to be in scope.<br><br></span></div><span class="im">Thanks for the help.<br></span></div><div class="gmail_extra"><br><div class="gmail_quote">2015-08-24 11:45 GMT-05:00 WK <span dir="ltr"><<a href="mailto:wanradt@gmail.com" target="_blank">wanradt@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">2015-08-24 18:52 GMT+03:00 Richard Reina <<a href="mailto:gatorreina@gmail.com">gatorreina@gmail.com</a>>:<br>
<br>
> Thank you very much for the reply. Before I saw this came up with this<br>
> solution to pass the variable to the other sub/template:<br>
><br>
> # take them to the add_sport (but with the id no)<br>
> hook 'before' => sub {<br>
> var S_id => $select_id;<br>
> request->path('/sport_add')<br>
> };<br>
><br>
> redirect '/sport_add';<br>
<br>
</span>You may need before-hook sometimes, but not now (if I understood you<br>
correctly). before-hook is executed on every request. Mostly you don't<br>
have need to set id such way for every route. For basic data<br>
submitting is best to submit data to post-route and after successful<br>
data-saving redirect to result page. Like this:<br>
<br>
post '/sport_add' => sub {<br>
my $id = params->{ id };<br>
# DO something to store needed data<br>
redirect "/sport_add/$id";<br>
};<br>
<span class=""><br>
get '/sport_add/:id' => sub {<br>
</span> my ( $id ) = params->{ id };<br>
template 'sport_add', { id => $id };<br>
<span class=""> };<br>
<br>
> It actually worked but I was wondering if doing it this way with hook and<br>
> redirect is a bad idea?<br>
<br>
</span>The before-hook was redundant there, redirect was right way.<br>
<br>
In cookbook is shown one way to use it:<br>
<a href="http://search.cpan.org/dist/Dancer/lib/Dancer/Cookbook.pod#Before_hooks_-_processed_before_a_request" rel="noreferrer" target="_blank">http://search.cpan.org/dist/Dancer/lib/Dancer/Cookbook.pod#Before_hooks_-_processed_before_a_request</a><br>
<span class=""><br>
> Also, I was wondering why it's a bad idea to print<br>
> input from dancer to the console? Does it produce a security vulnerability<br>
> or is it merely disruptive to dancer?<br>
<br>
</span>Have you tried to print there? You print into SТDOUT and you ruin<br>
http-headers, resulting faulty page. print does not send anything to<br>
console, use log-methods for it (like debug).<br>
<br>
Wbr,<br>
<div class="HOEnZb"><div class="h5">--<br>
Kõike hääd,<br>
<br>
Gunnar<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" rel="noreferrer" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</div></div></blockquote></div><br></div>