Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

how to add default value using hash value and delimiter to text area in template toolkit

by srins (Sexton)
on Nov 12, 2005 at 18:47 UTC ( #508001=perlquestion: print w/replies, xml ) Need Help??

srins has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

1.How to add default value to text area from my hash having one field as default=>"somevalue",how i need to add default value to test area from the hash below.

2.How to add delimiter other than spaces to text area. If I enter multiple value to the text area and submit the data using the form ,the text area multiple values are separated by space delimiter ,where this will fail for me if i have the values like

config data config values config data values

where if i use space as delimiter it fails as i getting config and data as separate values.So i need to use any delimiter such as $,in text area, and if user gives muliple entries i will separate using delimiters like $,how to add delimiter to text area.

hash function is my @add=( { name=>"comment", type =>"text", default=>"all", enum=>[" "], entries=>"single" }, { name=>"Submode", type =>"textarea", default=>"all ", enum=>[" "], entries=>"more" } ); [% FOREACH element = add %] [% IF element.type == "text" %] <input type="text" name="[%element.name %]" value="[%element.default +%]" size="58"> [% ELSE %] <textarea rows="4" name="[%element.name %]" > </textarea> [% END %] [% END %]

how to change my code accordingly to include default value in text area and also to use different delimeter other than space like $ or ,. please help me in this regard.

20051112 Janitored by Corion: Changed PRE into P tags

  • Comment on how to add default value using hash value and delimiter to text area in template toolkit
  • Select or Download Code

Replies are listed 'Best First'.
Re: how to add default value using hash value and delimiter to text area in template toolkit
by shenme (Priest) on Nov 12, 2005 at 22:06 UTC
    1) A <textarea> form element is different from the other <input> elements in that it has a beginning and ending tag, with the 'value' between those. Thus to start a textarea with the value "Howdy!" you would code
    <textarea>Howdy!</textarea>
    So it looks like you could add the value in your template by using
    <textarea rows="4" name="[% element.name %]">
    [% element.value %]
    </textarea>
    

    2) I'm not sure I understand your question. You can 'see' separate values if they are on separate lines in the textarea. You may have to check for CR or LF characters, and to do that you might have to force CR/LF characters by playing with the wrap parameter, such as

    <textarea wrap="hard"></textarea>
Re: how to add default value using hash value and delimiter to text area in template toolkit
by davidrw (Prior) on Nov 12, 2005 at 21:56 UTC
    More of an HTML question, but just have it print the value between the textarea tags .. Note i removed the line breaks -- if you leave them there they will be part of the default value.
    <textarea rows="4" name="[%element.name %]" >[% element.default %]</te +xtarea>
    As for the second part, it seems like you want to add the '$' or whatever delimiter to element.default before you pass it to the template -- may sometihng like $element->{default} =~ s/\n/\$/sg;

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2022-12-05 19:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?