textarea.php
Go to the documentation of this file.
1 <?php
10 namespace depage\htmlform\elements;
11 
34 class textarea extends text
35 {
45  protected function setDefaults()
46  {
47  parent::setDefaults();
48 
49  $this->defaults['rows'] = null;
50  $this->defaults['cols'] = null;
51  $this->defaults['autogrow'] = false;
52  }
53 
59  public function __toString()
60  {
61  $label = $this->htmlLabel();
62  $marker = $this->htmlMarker();
63  $inputAttributes = $this->htmlInputAttributes();
64  $value = $this->htmlValue();
65  $rows = $this->htmlRows();
66  $cols = $this->htmlCols();
67  $wrapperAttributes = $this->htmlWrapperAttributes();
69  $helpMessage = $this->htmlHelpMessage();
70 
71  return "<p {$wrapperAttributes}>" .
72  "<label>" .
73  "<span class=\"depage-label\">{$label}{$marker}</span>" .
74  "<textarea name=\"{$this->name}\"{$inputAttributes}{$rows}{$cols}>{$value}</textarea>" .
75  "</label>" .
77  $helpMessage .
78  "</p>\n";
79  }
80 
86  protected function htmlWrapperAttributes()
87  {
88  $attributes = parent::htmlWrapperAttributes();
89 
90  $options = array();
91  $options['autogrow'] = $this->autogrow;
92 
93  $attributes .= " data-textarea-options=\"" . $this->htmlEscape(json_encode($options)) . "\"";
94 
95  return $attributes;
96  }
102  protected function htmlRows()
103  {
104  return ($this->rows === null) ? "" : " rows=\"" . $this->htmlEscape($this->rows) . "\"";
105  }
111  protected function htmlCols()
112  {
113  return ($this->cols === null) ? "" : " cols=\"" . $this->htmlEscape($this->cols) . "\"";
114  }
115 }
116 
117 /* vim:set ft=php sw=4 sts=4 fdm=marker et : */
htmlEscape($options=array())
Escapes HTML in strings and arrays of strings.
Definition: element.php:193
htmlCols()
Renders HTML cols attribute.
Definition: textarea.php:111
htmlMarker()
Returns elements&#39; required-indicator.
Definition: input.php:445
htmlErrorMessage()
Returns HTML-rendered error message.
Definition: input.php:514
HTML text input type.
Definition: text.php:38
htmlValue()
Returns HTML-rendered element value.
Definition: input.php:504
htmlHelpMessage()
Returns HTML-rendered helpMessage.
Definition: input.php:533
$value
Input elements&#39;s value.
Definition: input.php:79
$label
Input element - HTML label.
Definition: input.php:36
htmlInputAttributes()
renders text element specific HTML attributes
Definition: text.php:142
HTML textarea element.
Definition: textarea.php:34
$errorMessage
Message that gets displayed in case of invalid input.
Definition: input.php:173
setDefaults()
collects initial values across subclasses
Definition: textarea.php:45
$helpMessage
Extra help message.
Definition: input.php:185
$marker
Input element - HTML marker text that marks required fields.
Definition: input.php:47
__toString()
Renders element to HTML.
Definition: textarea.php:59
htmlWrapperAttributes()
Returns string of HTML attributes for element wrapper paragraph.
Definition: textarea.php:86
htmlRows()
Renders HTML rows attribute.
Definition: textarea.php:102