Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: CGI to Dancer popup_menu

by choroba (Cardinal)
on Jan 15, 2015 at 14:23 UTC ( [id://1113332]=note: print w/replies, xml ) Need Help??


in reply to CGI to Dancer popup_menu

You should create the template from the output of the CGI, not from the code.
perl -MCGI=:standard -e 'print popup_menu({ -name => "query", -values => [1, 2, 3], -labels => {qw{ 2 label2 +1 label1 3 label3 }}, -default => 2 })' <select name="query" > <option value="1">label1</option> <option selected="selected" value="2">label2</option> <option value="3">label3</option> </select>

Update

So, using Template, the following seems to work:

Template call:

template 'index', { name => 'query', options => { label1 => 'Option 1', label2 => 'Option 2', label3 => 'Option 3', }, default => 'label2', };

The template:

<select name="<% name %>" > <%- FOR o IN options %> <option value="<% o.key %>" <%- IF o.key == default %> selected="selected" <% END -%> ><% o.value %></option> <%- END %> </select>
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: CGI to Dancer popup_menu
by Your Mother (Archbishop) on Jan 15, 2015 at 16:57 UTC

    A good habit for Template code is escape all template vars. That way DB/User-input strings can be plain/arbitrary without risk of XSS attacks.

    E.g.: <% name | html %>
Re^2: CGI to Dancer popup_menu
by adriang (Sexton) on Jan 15, 2015 at 18:21 UTC
    Thanks very much for the quick replay, I will try it right away.
      Thanks again, it was a success.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1113332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-20 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found