TYPO3 CMS  TYPO3_7-6
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  {
43  parent::initializeArguments();
44  $this->registerTagAttribute('autofocus', 'string', 'Specifies that an input should automatically get focus when the page loads');
45  $this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
46  $this->registerTagAttribute('maxlength', 'int', 'The maxlength attribute of the input field (will not be validated)');
47  $this->registerTagAttribute('readonly', 'string', 'The readonly attribute of the input field');
48  $this->registerTagAttribute('size', 'int', 'The size of the input field');
49  $this->registerTagAttribute('placeholder', 'string', 'The placeholder of the textfield');
50  $this->registerTagAttribute('pattern', 'string', 'HTML5 validation pattern');
51  $this->registerArgument('errorClass', 'string', 'CSS class to set if there are errors for this view helper', false, 'f3-form-error');
53  }
54 
63  public function render($required = false, $type = 'text')
64  {
65  $name = $this->getName();
67  $this->setRespectSubmittedDataValue(true);
68 
69  $this->tag->addAttribute('type', $type);
70  $this->tag->addAttribute('name', $name);
71 
72  $value = $this->getValueAttribute();
73 
74  if ($value !== null) {
75  $this->tag->addAttribute('value', $value);
76  }
77 
78  if ($required !== false) {
79  $this->tag->addAttribute('required', 'required');
80  }
81 
83  $this->setErrorClassAttribute();
84 
85  return $this->tag->render();
86  }
87 }
registerArgument($name, $type, $description, $required=false, $defaultValue=null)
registerTagAttribute($name, $type, $description, $required=false, $default=null)