TYPO3 CMS  TYPO3_6-2
TextfieldViewHelper.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
29 
33  protected $tagName = 'input';
34 
41  public function initializeArguments() {
42  parent::initializeArguments();
43  $this->registerTagAttribute('autofocus', 'string', 'Specifies that a input should automatically get focus when the page loads');
44  $this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
45  $this->registerTagAttribute('maxlength', 'int', 'The maxlength attribute of the input field (will not be validated)');
46  $this->registerTagAttribute('readonly', 'string', 'The readonly attribute of the input field');
47  $this->registerTagAttribute('size', 'int', 'The size of the input field');
48  $this->registerTagAttribute('placeholder', 'string', 'The placeholder of the textfield');
49  $this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this view helper', FALSE, 'f3-form-error');
51  }
52 
61  public function render($required = NULL, $type = 'text') {
62  $name = $this->getName();
64 
65  $this->tag->addAttribute('type', $type);
66  $this->tag->addAttribute('name', $name);
67 
68  $value = $this->getValue();
69 
70  if ($value !== NULL) {
71  $this->tag->addAttribute('value', $value);
72  }
73 
74  if ($required !== NULL) {
75  $this->tag->addAttribute('required', 'required');
76  }
77 
78  $this->setErrorClassAttribute();
79 
80  return $this->tag->render();
81  }
82 }
registerTagAttribute($name, $type, $description, $required=FALSE, $default=NULL)
registerArgument($name, $type, $description, $required=FALSE, $defaultValue=NULL)