[BUGFIX] Submitted form data has precedence over value argument
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Form / ButtonViewHelper.php
1 <?php
2
3 namespace TYPO3\CMS\Fluid\ViewHelpers\Form;
4
5 /* *
6 * This script belongs to the FLOW3 package "TYPO3.Fluid". *
7 * *
8 * It is free software; you can redistribute it and/or modify it under *
9 * the terms of the GNU Lesser General Public License, either version 3 *
10 * of the License, or (at your option) any later version. *
11 * *
12 * The TYPO3 project - inspiring people to share! *
13 * */
14
15 /**
16 * Creates a button.
17 *
18 * = Examples =
19 *
20 * <code title="Defaults">
21 * <f:form.button>Send Mail</f:form.button>
22 * </code>
23 * <output>
24 * <button type="submit" name="" value="">Send Mail</button>
25 * </output>
26 *
27 * <code title="Disabled cancel button with some HTML5 attributes">
28 * <f:form.button type="reset" name="buttonName" value="buttonValue" disabled="disabled" formmethod="post" formnovalidate="formnovalidate">Cancel</f:form.button>
29 * </code>
30 * <output>
31 * <button disabled="disabled" formmethod="post" formnovalidate="formnovalidate" type="reset" name="myForm[buttonName]" value="buttonValue">Cancel</button>
32 * </output>
33 *
34 * @api
35 */
36 class ButtonViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormFieldViewHelper {
37
38 /**
39 * @var string
40 */
41 protected $tagName = 'button';
42
43 /**
44 * Initialize the arguments.
45 *
46 * @return void
47 * @api
48 */
49 public function initializeArguments() {
50 parent::initializeArguments();
51 $this->registerTagAttribute(
52 'autofocus', 'string', 'Specifies that a button should automatically get focus when the page loads'
53 );
54 $this->registerTagAttribute(
55 'disabled', 'string', 'Specifies that the input element should be disabled when the page loads'
56 );
57 $this->registerTagAttribute('form', 'string', 'Specifies one or more forms the button belongs to');
58 $this->registerTagAttribute(
59 'formaction', 'string',
60 'Specifies where to send the form-data when a form is submitted. Only for type="submit"'
61 );
62 $this->registerTagAttribute(
63 'formenctype', 'string',
64 '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")'
65 );
66 $this->registerTagAttribute(
67 'formmethod', 'string',
68 'Specifies how to send the form-data (which HTTP method to use). Only for type="submit" (e.g. "get" or "post")'
69 );
70 $this->registerTagAttribute(
71 'formnovalidate', 'string',
72 'Specifies that the form-data should not be validated on submission. Only for type="submit"'
73 );
74 $this->registerTagAttribute(
75 'formtarget', 'string',
76 'Specifies where to display the response after submitting the form. Only for type="submit" (e.g. "_blank", "_self", "_parent", "_top", "framename")'
77 );
78 $this->registerUniversalTagAttributes();
79 }
80
81 /**
82 * Renders the button.
83 *
84 * @param string $type Specifies the type of button (e.g. "button", "reset" or "submit")
85 * @return string
86 * @api
87 */
88 public function render($type = 'submit') {
89 $name = $this->getName();
90 $this->registerFieldNameForFormTokenGeneration($name);
91
92 $this->tag->addAttribute('type', $type);
93 $this->tag->addAttribute('name', $name);
94 $this->tag->addAttribute('value', $this->getValueAttribute());
95 $this->tag->setContent($this->renderChildren());
96
97 return $this->tag->render();
98 }
99
100 }