Packages

  • Nette
    • Application
    • Caching
    • Collections
    • Config
    • Forms
    • IO
    • Loaders
    • Mail
    • Reflection
    • Security
    • Templates
    • Web
  • None
  • PHP

Classes

  • NButton
  • NCheckbox
  • NConventionalRenderer
  • NFileUpload
  • NForm
  • NFormContainer
  • NFormGroup
  • NHiddenField
  • NImageButton
  • NInstantClientScript
  • NMultiSelectBox
  • NRadioList
  • NRule
  • NRules
  • NSelectBox
  • NSubmitButton
  • NTextArea
  • NTextBase
  • NTextInput

Interfaces

  • IFormControl
  • IFormRenderer
  • INamingContainer
  • ISubmitterControl
  • Overview
  • Package
  • Class
  • Tree
  • Other releases
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  *
 6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  * @package Nette\Forms
11:  */
12: 
13: 
14: 
15: /**
16:  * Single line text input control.
17:  *
18:  * @author     David Grudl
19:  * @package Nette\Forms
20:  */
21: class NTextInput extends NTextBase
22: {
23: 
24:     /**
25:      * @param  string  control name
26:      * @param  string  label
27:      * @param  int  width of the control
28:      * @param  int  maximum number of characters the user may enter
29:      */
30:     public function __construct($label = NULL, $cols = NULL, $maxLength = NULL)
31:     {
32:         parent::__construct($label);
33:         $this->control->type = 'text';
34:         $this->control->size = $cols;
35:         $this->control->maxlength = $maxLength;
36:         $this->filters[] = callback($this, 'sanitize');
37:         $this->value = '';
38:     }
39: 
40: 
41: 
42:     /**
43:      * Filter: removes unnecessary whitespace and shortens value to control's max length.
44:      * @return string
45:      */
46:     public function sanitize($value)
47:     {
48:         if ($this->control->maxlength && iconv_strlen($value, 'UTF-8') > $this->control->maxlength) {
49:             $value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
50:         }
51:         return NString::trim(strtr($value, "\r\n", '  '));
52:     }
53: 
54: 
55: 
56:     /**
57:      * Sets or unsets the password mode.
58:      * @param  bool
59:      * @return NTextInput  provides a fluent interface
60:      */
61:     public function setPasswordMode($mode = TRUE)
62:     {
63:         $this->control->type = $mode ? 'password' : 'text';
64:         return $this;
65:     }
66: 
67: 
68: 
69:     /**
70:      * Generates control's HTML element.
71:      * @return NHtml
72:      */
73:     public function getControl()
74:     {
75:         $control = parent::getControl();
76:         if ($this->control->type !== 'password') {
77:             $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value;
78:         }
79:         return $control;
80:     }
81: 
82: 
83: 
84:     public function notifyRule(NRule $rule)
85:     {
86:         if (is_string($rule->operation) && strcasecmp($rule->operation, ':length') === 0 && !$rule->isNegative) {
87:             $this->control->maxlength = is_array($rule->arg) ? $rule->arg[1] : $rule->arg;
88: 
89:         } elseif (is_string($rule->operation) && strcasecmp($rule->operation, ':maxLength') === 0 && !$rule->isNegative) {
90:             $this->control->maxlength = $rule->arg;
91:         }
92: 
93:         parent::notifyRule($rule);
94:     }
95: 
96: 
97: }
98: 
Nette Framework 0.9.7 (for PHP 5.2) API documentation generated by ApiGen 2.3.0