Recent Changes - Search:

Cookbook

PmWiki

pmwiki.org

Multiline textareas

Summary: How to create textareas pre-filled with content
Maintainer: Petko
Categories: Forms Obsolete
License: PD
Note: This recipe is probably not needed if you are using PmWiki 2.2.0beta45 or later.

From this version onwards (:input textarea...:) can handle default text (including values loaded from $InputValues).

To specify a multiline textarea content in the wiki page, enclose it with value=[=...content here...=].

(:input form:)
(:input textarea t1 value="[=Multiline
content=]" cols=20 rows=3:)
(:input textarea t2 [=Multi
line
content=] cols=20 rows=3:)
(:input end:)

Questions answered by this recipe

How to pre-fill a "textarea" input control with a value? (From the wiki page or from a script).
How to preserve textarea content when posting is unsuccessful and you are returned to the form?

Markup allowing to create textareas pre-filled with content The default PmWiki Forms (:input textarea:) markup was only able to produce empty text areas.

This recipe adds a new (:textarea:)(:textareaend:) markup command.

Markup('textarea', '<split',
  '/\\(:textarea\\s*(.*?):\\)(.*?)\\(:textareaend:\\)/esi',
  "FmtTextArea(\$pagename,PSS('$1'),PSS('$2'))");
function FmtTextArea($pagename, $args, $value)
{
  global $InputValues;
  $opt = ParseArgs($args);
  if (@$opt[''][0]>'' && ! @$opt['name'])$opt['name'] = $opt[''][0];
  $attributes = array('name', 'id', 'class', 'rows', 'cols',
        'maxlength', 'accesskey', 'disabled', 'readonly', 'style');
  $myattr = "";
  foreach($attributes as $k)
  {   if(isset($opt[$k])) $myattr.=" $k=\"".htmlspecialchars($opt[$k])."\"";}
  if(!strlen($value))$value = htmlspecialchars(@$InputValues[@$opt['name']]);
  return Keep(FmtPageName("<textarea $myattr>$value</textarea>", $pagename));
}
You can write
(:textarea name=area1 cols=40 rows=4 class=inputbox:)Some text
New line.(:textareaend:)

Perhaps more importantly, it is possible to pre-populate the content from a script/recipe with the $InputValues array. See a section in InputDefault. (I am using it this way). Hope this helps somebody. --Petko

Notes

If you're entering markup in the text area, line breaks like \\ should be entered as \\\\ --SteP

Not in my installation: a new line is output as a new line inside the textarea, \\ is output as \\. --Petko

Preserving content

You can preserve content entered into the textarea, so if a posting error occurs, and you are returned to the form, your typed in content is still there. Add to a local config file:

# POST input values will be preserved
foreach ($_POST as $k=>$v) {
   if(!is_array($v)) 
     $InputValues[$k] = htmlspecialchars($v);
}

I am using this now for all general form text input, in FoxForum and other Fox applications. HansB

Release Notes

Comments

Hi Petko, this is a very helpful markup! Is it possible to modify it so one can enter into the markup the name without having to write name=text for instance, like (:textarea text :)(:textareaend:), the same as it is possible with (:input:) markup? I keep forgetting to type name= . HansB April 19, 2007, at 03:36 AM

Good idea, I made a change and now it works this way: if there is a "name=" attribute, it is used, otherwise, the first "standalone" attribute will be the name, like: (:textarea Field1 cols=40 rows=2:). --Petko April 19, 2007, at 04:23 AM
Thanks! Perfect! HansB

I see in the page history that there's some controversy about whether this recipe is deprecated or not. As far as I can tell, (:input textarea:) and (:input default:) do not allow line breaks in default values. Since support for line breaks is one of the main reasons to use a textarea reather than a text input, it seems to me that this recipe (or equivalent, such as the one provided by ZAP) will be needed until such time as line breaks are supported. Let me know if I'm wrong about that.
Ben Stallings June 10, 2007, at 10:06 AM

See this message from Pm [1] : yes, as of today, the recipe may be of some use. However, from inside another recipe, the $InputValues array should work with multiline values for "input textarea". --Petko June 14, 2007, at 05:09 PM

The input textarea field now accepts multiline content if wrapped with [=...=], so I am marking this recipe as obsolete. This page could, however, be useful for people searching for this feature to find it. --Petko August 26, 2009, at 08:57 AM

See Also

Contributors

Edit - History - Print - Recent Changes - Search
Page last modified on July 18, 2014, at 02:33 AM