|
Cookbook /
TextareaNote: This recipe is not needed if you are using PmWiki 2.2.0beta45 or later. Questions answered by this recipeHow to pre-fill a "textarea" input control with a value? (From the wiki page or from a script). DescriptionMarkup allowing to create textareas pre-filled with content
The default PmWiki Forms This recipe adds a new
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));
}
(: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 NotesIf 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 contentYou 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
CommentsHi 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 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. 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
See AlsoContributors |