Skip to content
Permalink
Browse files

Changing FormHelper::submit() to be able to create all types of submi…

…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 08f07a9aa4a42530f477b6f81993b610493f7ba8
@@ -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) {
@@ -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 {
@@ -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/>',
@@ -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'),

0 comments on commit 08f07a9

Please sign in to comment.
You can’t perform that action at this time.