[TASK] Sync CMS Fluid with Flow Fluid 1.1 (part1)
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Form / ButtonViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
3
4 /* *
5 * This script belongs to the FLOW3 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
14 /**
15 * Creates a button.
16 *
17 * = Examples =
18 *
19 * <code title="Defaults">
20 * <f:form.button>Send Mail</f:form.button>
21 * </code>
22 * <output>
23 * <button type="submit" name="" value="">Send Mail</button>
24 * </output>
25 *
26 * <code title="Disabled cancel button with some HTML5 attributes">
27 * <f:form.button type="reset" name="buttonName" value="buttonValue" disabled="disabled" formmethod="post" formnovalidate="formnovalidate">Cancel</f:form.button>
28 * </code>
29 * <output>
30 * <button disabled="disabled" formmethod="post" formnovalidate="formnovalidate" type="reset" name="myForm[buttonName]" value="buttonValue">Cancel</button>
31 * </output>
32 *
33 * @api
34 */
35 class ButtonViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper {
36
37 /**
38 * @var string
39 */
40 protected $tagName = 'button';
41
42 /**
43 * Initialize the arguments.
44 *
45 * @return void
46 * @api
47 */
48 public function initializeArguments() {
49 parent::initializeArguments();
50 $this->registerTagAttribute('autofocus', 'string', 'Specifies that a button should automatically get focus when the page loads');
51 $this->registerTagAttribute('disabled', 'string', 'Specifies that the input element should be disabled when the page loads');
52 $this->registerTagAttribute('form', 'string', 'Specifies one or more forms the button belongs to');
53 $this->registerTagAttribute('formaction', 'string', 'Specifies where to send the form-data when a form is submitted. Only for type="submit"');
54 $this->registerTagAttribute('formenctype', 'string', 'Specifies how form-data should be encoded before sending it to a server. Only for type="submit" (e.g. "application/x-www-form-urlencoded", "multipart/form-data" or "text/plain")');
55 $this->registerTagAttribute('formmethod', 'string', 'Specifies how to send the form-data (which HTTP method to use). Only for type="submit" (e.g. "get" or "post")');
56 $this->registerTagAttribute('formnovalidate', 'string', 'Specifies that the form-data should not be validated on submission. Only for type="submit"');
57 $this->registerTagAttribute('formtarget', 'string', 'Specifies where to display the response after submitting the form. Only for type="submit" (e.g. "_blank", "_self", "_parent", "_top", "framename")');
58 $this->registerUniversalTagAttributes();
59 }
60
61 /**
62 * Renders the button.
63 *
64 * @param string $type Specifies the type of button (e.g. "button", "reset" or "submit")
65 * @return string
66 * @api
67 */
68 public function render($type = 'submit') {
69 $name = $this->getName();
70 $this->registerFieldNameForFormTokenGeneration($name);
71
72 $this->tag->addAttribute('type', $type);
73 $this->tag->addAttribute('name', $name);
74 $this->tag->addAttribute('value', $this->getValue());
75 $this->tag->setContent($this->renderChildren());
76
77 return $this->tag->render();
78 }
79 }
80
81 ?>