diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index bf2c21c19..9133612b9 100644 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -891,33 +891,23 @@ class FormHelper extends AppHelper { /** * Creates a button tag. * - * @param mixed $params Array of params [content, type, options] or the - * content of the button. - * @param string $type Type of the button (button, submit or reset). + * @param string $title The button's caption * @param array $options Array of options. * @return string A HTML button tag. * @access public */ - function button($params, $type = 'button', $options = array()) { + function button($title, $options = array()) { + $options = array_merge(array('type' => 'button', 'value' => $title), $options); - trigger_error(__("Don't use me yet"), E_USER_ERROR); - if (isset($options['name'])) { - if (strpos($options['name'], "/") !== false || strpos($options['name'], ".") !== false) { - if ($this->value($options['name'])) { - $options['checked'] = 'checked'; - } - $this->setFieldName($options['name']); - $options['name'] = 'data[' . $this->model() . '][' . $this->field() . ']'; + if (isset($options['name']) && (strpos($options['name'], "/") !== false || strpos($options['name'], ".") !== false)) { + if ($this->value($options['name'])) { + $options['checked'] = 'checked'; } + $name = $options['name']; + unset($options['name']); + $options = $this->__initInputField($name, $options); } - - $options['type'] = $type; - - $values = array( - 'options' => $this->_parseOptions($options), - 'tagValue' => $content - ); - return $this->_assign('button', $values); + return $this->output(sprintf($this->Html->tags['button'], $options['type'], $this->_parseAttributes($options, array('type'), '', ' '))); } /** * Creates a submit button element. diff --git a/cake/libs/view/helpers/html.php b/cake/libs/view/helpers/html.php index c04c3d0bb..b5c34ed5a 100644 --- a/cake/libs/view/helpers/html.php +++ b/cake/libs/view/helpers/html.php @@ -69,6 +69,7 @@ class HtmlHelper extends AppHelper { 'file_no_model' => '', 'submit' => '', 'submitimage' => '', + 'button' => '', 'image' => '', 'tableheader' => '%s', 'tableheaderrow' => '%s', diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index b7cd293b4..c5c35015a 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -1153,6 +1153,30 @@ class FormHelperTest extends CakeTestCase { $this->assertNoPattern('/]+[^(type|name|value|id)]=[^<>]*>$/', $result); } + function testButton() { + $result = $this->Form->button('Hi'); + $expected = ''; + $this->assertEqual($result, $expected); + + $result = $this->Form->button('Clear Form', array('type' => 'clear')); + $expected = ''; + $this->assertEqual($result, $expected); + + $result = $this->Form->button('Reset Form', array('type' => 'reset')); + $expected = ''; + $this->assertEqual($result, $expected); + + $result = $this->Form->button('Options', array('type' => 'reset', 'name' => 'Post.options')); + $this->assertPattern('/^]+ \/>$/', $result); + $this->assertPattern('/^]+value="Options"[^<>]+\/>$/', $result); + $this->assertPattern('/^]+name="data\[Post\]\[options\]"[^<>]+\/>$/', $result); + $this->assertPattern('/^]+id="PostOptions"[^<>]+\/>$/', $result); + + $result = $this->Form->button('Options', array('type' => 'reset', 'name' => 'Post.options', 'id' => 'Opt')); + $this->assertPattern('/^]+id="Opt"[^<>]+\/>$/', $result); + $this->assertNoPattern('/^]+id=[^<>]+id=/', $result); + } + function testSubmitButton() { $result = $this->Form->submit('Test Submit'); $this->assertPattern('/^]+value="Test Submit"[^<>]+\/><\/div>$/', $result);