Namespaces

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

Classes

  • Button
  • Checkbox
  • ConventionalRenderer
  • FileUpload
  • Form
  • FormContainer
  • FormControl
  • FormGroup
  • HiddenField
  • ImageButton
  • InstantClientScript
  • MultiSelectBox
  • RadioList
  • Rule
  • Rules
  • SelectBox
  • SubmitButton
  • TextArea
  • TextBase
  • TextInput

Interfaces

  • IFormControl
  • IFormRenderer
  • INamingContainer
  • ISubmitterControl
  • Overview
  • Namespace
  • 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:  */
 11: 
 12: namespace Nette\Forms;
 13: 
 14: use Nette;
 15: 
 16: 
 17: 
 18: /**
 19:  * Single line text input control.
 20:  *
 21:  * @author     David Grudl
 22:  */
 23: class TextInput extends TextBase
 24: {
 25: 
 26:     /**
 27:      * @param  string  control name
 28:      * @param  string  label
 29:      * @param  int  width of the control
 30:      * @param  int  maximum number of characters the user may enter
 31:      */
 32:     public function __construct($label = NULL, $cols = NULL, $maxLength = NULL)
 33:     {
 34:         parent::__construct($label);
 35:         $this->control->type = 'text';
 36:         $this->control->size = $cols;
 37:         $this->control->maxlength = $maxLength;
 38:         $this->filters[] = callback($this, 'sanitize');
 39:         $this->value = '';
 40:     }
 41: 
 42: 
 43: 
 44:     /**
 45:      * Filter: removes unnecessary whitespace and shortens value to control's max length.
 46:      * @return string
 47:      */
 48:     public function sanitize($value)
 49:     {
 50:         if ($this->control->maxlength && iconv_strlen($value, 'UTF-8') > $this->control->maxlength) {
 51:             $value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
 52:         }
 53:         return Nette\String::trim(strtr($value, "\r\n", '  '));
 54:     }
 55: 
 56: 
 57: 
 58:     /**
 59:      * Sets or unsets the password mode.
 60:      * @param  bool
 61:      * @return TextInput  provides a fluent interface
 62:      */
 63:     public function setPasswordMode($mode = TRUE)
 64:     {
 65:         $this->control->type = $mode ? 'password' : 'text';
 66:         return $this;
 67:     }
 68: 
 69: 
 70: 
 71:     /**
 72:      * Generates control's HTML element.
 73:      * @return Nette\Web\Html
 74:      */
 75:     public function getControl()
 76:     {
 77:         $control = parent::getControl();
 78:         if ($this->control->type !== 'password') {
 79:             $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value;
 80:         }
 81:         return $control;
 82:     }
 83: 
 84: 
 85: 
 86:     public function notifyRule(Rule $rule)
 87:     {
 88:         if (is_string($rule->operation) && strcasecmp($rule->operation, ':length') === 0 && !$rule->isNegative) {
 89:             $this->control->maxlength = is_array($rule->arg) ? $rule->arg[1] : $rule->arg;
 90: 
 91:         } elseif (is_string($rule->operation) && strcasecmp($rule->operation, ':maxLength') === 0 && !$rule->isNegative) {
 92:             $this->control->maxlength = $rule->arg;
 93:         }
 94: 
 95:         parent::notifyRule($rule);
 96:     }
 97: 
 98: 
 99: }
100: 
Nette Framework 0.9.7 API documentation generated by ApiGen 2.3.0