Skip to content

Commit

Permalink
Changing FormHelper::submit() to be able to create all types of submi…
Browse files Browse the repository at this point in the history
…t buttons. Use 'type' option to create reset or button type inputs.

Test cases added.
  • Loading branch information
markstory committed Oct 20, 2009
1 parent b9e28d1 commit 08f07a9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cake/libs/view/helpers/form.php
Expand Up @@ -1153,6 +1153,7 @@ function submit($caption = null, $options = array()) {
$div = $options['div'];
unset($options['div']);
}
$options += array('type' => 'submit');
$divOptions = array('tag' => 'div');

if ($div === true) {
Expand All @@ -1166,12 +1167,14 @@ function submit($caption = null, $options = array()) {
}

if (strpos($caption, '://') !== false) {
unset($options['type']);
$out .= $this->output(sprintf(
$this->Html->tags['submitimage'],
$caption,
$this->_parseAttributes($options, null, '', ' ')
));
} elseif (preg_match('/\.(jpg|jpe|jpeg|gif|png|ico)$/', $caption)) {
unset($options['type']);
if ($caption{0} !== '/') {
$url = $this->webroot(IMAGES_URL . $caption);
} else {
Expand Down
2 changes: 1 addition & 1 deletion cake/libs/view/helpers/html.php
Expand Up @@ -58,7 +58,7 @@ class HtmlHelper extends AppHelper {
'password' => '<input type="password" name="%s" %s/>',
'file' => '<input type="file" name="%s" %s/>',
'file_no_model' => '<input type="file" name="%s" %s/>',
'submit' => '<input type="submit" %s/>',
'submit' => '<input %s/>',
'submitimage' => '<input type="image" src="%s" %s/>',
'button' => '<input type="%s" %s/>',
'image' => '<img src="%s" %s/>',
Expand Down
23 changes: 23 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -4560,6 +4560,29 @@ function testSubmitButton() {
);
$this->assertTags($result, $expected);

$result = $this->Form->submit('Next >', array('escape' => false));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'submit', 'value' => 'Next >'),
'/div'
);
$this->assertTags($result, $expected);

$result = $this->Form->submit('Reset!', array('type' => 'reset'));
$expected = array(
'div' => array('class' => 'submit'),
'input' => array('type' => 'reset', 'value' => 'Reset!'),
'/div'
);
$this->assertTags($result, $expected);
}

/**
* test image submit types.
*
* @return void
**/
function testSubmitImage() {
$result = $this->Form->submit('http://example.com/cake.power.gif');
$expected = array(
'div' => array('class' => 'submit'),
Expand Down

0 comments on commit 08f07a9

Please sign in to comment.