diff --git a/cake/libs/view/helpers/form.php b/cake/libs/view/helpers/form.php index 43cdf9e039d..c92c78ed1bf 100755 --- a/cake/libs/view/helpers/form.php +++ b/cake/libs/view/helpers/form.php @@ -1206,13 +1206,24 @@ function submit($caption = null, $options = array()) { $divOptions = array_merge(array('class' => 'submit', 'tag' => 'div'), $div); } + $before = ""; + $after = ""; + if (isset($options['before'])) { + $before = $options['before']; + unset($options['before']); + } + if (isset($options['after'])) { + $after = $options['after']; + unset($options['after']); + } + if (strpos($caption, '://') !== false) { unset($options['type']); - $out .= $this->output(sprintf( + $out .= $this->output($before . sprintf( $this->Html->tags['submitimage'], $caption, $this->_parseAttributes($options, null, '', ' ') - )); + ) . $after); } elseif (preg_match('/\.(jpg|jpe|jpeg|gif|png|ico)$/', $caption)) { unset($options['type']); if ($caption{0} !== '/') { @@ -1221,17 +1232,17 @@ function submit($caption = null, $options = array()) { $caption = trim($caption, '/'); $url = $this->webroot($caption); } - $out .= $this->output(sprintf( + $out .= $this->output($before . sprintf( $this->Html->tags['submitimage'], $url, $this->_parseAttributes($options, null, '', ' ') - )); + ) . $after); } else { $options['value'] = $caption; - $out .= $this->output(sprintf( + $out .= $this->output($before . sprintf( $this->Html->tags['submit'], $this->_parseAttributes($options, null, '', ' ') - )); + ). $after); } if (isset($divOptions)) { diff --git a/cake/tests/cases/libs/view/helpers/form.test.php b/cake/tests/cases/libs/view/helpers/form.test.php index 086d40e884a..f626834f978 100644 --- a/cake/tests/cases/libs/view/helpers/form.test.php +++ b/cake/tests/cases/libs/view/helpers/form.test.php @@ -4667,6 +4667,36 @@ function testSubmitButton() { '/div' ); $this->assertTags($result, $expected); + + $before = '--before--'; + $after = '--after--'; + $result = $this->Form->submit('Test', array('before' => $before)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'submit', 'value' => 'Test'), + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('Test', array('after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + 'input' => array('type' => 'submit', 'value' => 'Test'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('Test', array('before' => $before, 'after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'submit', 'value' => 'Test'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); } /** @@ -4706,6 +4736,46 @@ function testSubmitImage() { '/div' ); $this->assertTags($result, $expected); + + $after = '--after--'; + $before = '--before--'; + $result = $this->Form->submit('cake.power.gif', array('after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('cake.power.gif', array('before' => $before)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'), + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('cake.power.gif', array('before' => $before, 'after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'image', 'src' => 'img/cake.power.gif'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); + + $result = $this->Form->submit('Not.an.image', array('before' => $before, 'after' => $after)); + $expected = array( + 'div' => array('class' => 'submit'), + '--before--', + 'input' => array('type' => 'submit', 'value' => 'Not.an.image'), + '--after--', + '/div' + ); + $this->assertTags($result, $expected); } /**