Skip to content

Commit

Permalink
Added 'before' and 'after' options to FormHelper::submit(). Test case…
Browse files Browse the repository at this point in the history
…s updated.

Signed-off-by: Mark Story <mark@mark-story.com>
  • Loading branch information
tPl0ch authored and markstory committed Oct 31, 2009
1 parent a855a6a commit 2331cfd
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
23 changes: 17 additions & 6 deletions cake/libs/view/helpers/form.php
Expand Up @@ -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} !== '/') {
Expand All @@ -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)) {
Expand Down
70 changes: 70 additions & 0 deletions cake/tests/cases/libs/view/helpers/form.test.php
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down

0 comments on commit 2331cfd

Please sign in to comment.