Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
    • Templating
    • Utils
  • NetteModule
  • None
  • PHP

Classes

  • BaseControl
  • Button
  • Checkbox
  • HiddenField
  • ImageButton
  • MultiSelectBox
  • RadioList
  • SelectBox
  • SubmitButton
  • TextArea
  • TextBase
  • TextInput
  • UploadControl
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * This file is part of the Nette Framework (http://nette.org)
  5:  *
  6:  * Copyright (c) 2004, 2011 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\Controls;
 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 && Nette\Utils\Strings::length($value) > $this->control->maxlength) {
 51:             $value = iconv_substr($value, 0, $this->control->maxlength, 'UTF-8');
 52:         }
 53:         return Nette\Utils\Strings::trim(strtr($value, "\r\n", '  '));
 54:     }
 55: 
 56: 
 57: 
 58:     /**
 59:      * Changes control's type attribute.
 60:      * @param  string
 61:      * @return BaseControl  provides a fluent interface
 62:      */
 63:     public function setType($type)
 64:     {
 65:         $this->control->type = $type;
 66:         return $this;
 67:     }
 68: 
 69: 
 70: 
 71:     /** @deprecated */
 72:     public function setPasswordMode($mode = TRUE)
 73:     {
 74:         $this->control->type = $mode ? 'password' : 'text';
 75:         return $this;
 76:     }
 77: 
 78: 
 79: 
 80:     /**
 81:      * Generates control's HTML element.
 82:      * @return Nette\Utils\Html
 83:      */
 84:     public function getControl()
 85:     {
 86:         $control = parent::getControl();
 87:         foreach ($this->getRules() as $rule) {
 88:             if ($rule->isNegative || $rule->type !== Nette\Forms\Rule::VALIDATOR) {
 89: 
 90:             } elseif ($rule->operation === Nette\Forms\Form::RANGE && $control->type !== 'text') {
 91:                 list($control->min, $control->max) = $rule->arg;
 92: 
 93:             } elseif ($rule->operation === Nette\Forms\Form::PATTERN) {
 94:                 $control->pattern = $rule->arg;
 95:             }
 96:         }
 97:         if ($control->type !== 'password') {
 98:             $control->value = $this->getValue() === '' ? $this->translate($this->emptyValue) : $this->value;
 99:         }
100:         return $control;
101:     }
102: 
103: }
104: 
Nette Framework 2.0beta1 API API documentation generated by ApiGen 2.3.0