[dancer-users] Template Toolkit Help

John Stoffel john at stoffel.org
Thu Oct 1 23:14:59 BST 2015

>>>>> "Richard" == Richard Reina <gatorreina at gmail.com> writes:

Richard> 2015-09-21 13:20 GMT-05:00 Andrew Beverley
Richard> <andy at andybev.com>:

Richard> On Mon, 2015-09-21 at 13:09 -0500, Richard Reina wrote:
>> I have learned how to display variables in template toolkit with <%
>> varname %>. However, these variables are being named from withing
>> my dancer app and displayed on the template. Is there a way to
>> display variables that a user is entering as they are entering it.
Richard> Not as part of TT - that all happens server side.
>>   So that if I have a menu like form where a user can pick several
>> items and see them each added one by one in a list format before
>> pressing a second submit button that submits his entire lists of
>> entries? It would be a bit like a shopping cart but instead of the
>> items being put in the cart they are displayed right there in the
>> form as they are added.
Richard> In which case you have 2 options:
Richard> 1. Process it client-side with javascript (not recommended)
Richard> 2. Make each "addition" a new request, and store server-side
Richard> You could also do a combination with AJAX-type calls, which
Richard> is probably the best "modern" way of doing it, although it
Richard> will be more complicated than option 2.
Richard> Andy

Richard> I have gone the with option 2. Basically I have two forms in
Richard> the template. Form 1 lets the user add an item. Form 2 keeps
Richard> a running tally of the items thus far added. What I can't
Richard> figure out is how to make dancer differentiate between the
Richard> two forms so that it knows that the user is done adding items
Richard> and wants to check out so to speak he can hit the submit
Richard> button of Form 2 to save all his submissions. Both forms have
Richard> submit buttons but I am not sure how to make the POST route
Richard> understand that the user is done with the form so that I can
Richard> in turn make it save the data.

Umm... each form has it's own POST target?  Or instead of two forms,
you keep the running totals in DB with the keybeing the sessionID for
that session.  When they click on the main "submit" button, it just
does a call to the page which totals it all up and presents things for
final submission.

So you'd just one form, which is for entering things.  And then a
seperate javascript button which calls in to do the final wrap up.  

Does this make sense?  Sorry I don't have example code...


More information about the dancer-users mailing list