mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Changing FormHelper::submit() to be able to create all types of submit buttons. Use 'type' option to create reset or button type inputs.
Test cases added.
This commit is contained in:
parent
b9e28d1908
commit
08f07a9aa4
3 changed files with 27 additions and 1 deletions
|
@ -1153,6 +1153,7 @@ class FormHelper extends AppHelper {
|
||||||
$div = $options['div'];
|
$div = $options['div'];
|
||||||
unset($options['div']);
|
unset($options['div']);
|
||||||
}
|
}
|
||||||
|
$options += array('type' => 'submit');
|
||||||
$divOptions = array('tag' => 'div');
|
$divOptions = array('tag' => 'div');
|
||||||
|
|
||||||
if ($div === true) {
|
if ($div === true) {
|
||||||
|
@ -1166,12 +1167,14 @@ class FormHelper extends AppHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strpos($caption, '://') !== false) {
|
if (strpos($caption, '://') !== false) {
|
||||||
|
unset($options['type']);
|
||||||
$out .= $this->output(sprintf(
|
$out .= $this->output(sprintf(
|
||||||
$this->Html->tags['submitimage'],
|
$this->Html->tags['submitimage'],
|
||||||
$caption,
|
$caption,
|
||||||
$this->_parseAttributes($options, null, '', ' ')
|
$this->_parseAttributes($options, null, '', ' ')
|
||||||
));
|
));
|
||||||
} elseif (preg_match('/\.(jpg|jpe|jpeg|gif|png|ico)$/', $caption)) {
|
} elseif (preg_match('/\.(jpg|jpe|jpeg|gif|png|ico)$/', $caption)) {
|
||||||
|
unset($options['type']);
|
||||||
if ($caption{0} !== '/') {
|
if ($caption{0} !== '/') {
|
||||||
$url = $this->webroot(IMAGES_URL . $caption);
|
$url = $this->webroot(IMAGES_URL . $caption);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -58,7 +58,7 @@ class HtmlHelper extends AppHelper {
|
||||||
'password' => '<input type="password" name="%s" %s/>',
|
'password' => '<input type="password" name="%s" %s/>',
|
||||||
'file' => '<input type="file" name="%s" %s/>',
|
'file' => '<input type="file" name="%s" %s/>',
|
||||||
'file_no_model' => '<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/>',
|
'submitimage' => '<input type="image" src="%s" %s/>',
|
||||||
'button' => '<input type="%s" %s/>',
|
'button' => '<input type="%s" %s/>',
|
||||||
'image' => '<img src="%s" %s/>',
|
'image' => '<img src="%s" %s/>',
|
||||||
|
|
|
@ -4560,6 +4560,29 @@ class FormHelperTest extends CakeTestCase {
|
||||||
);
|
);
|
||||||
$this->assertTags($result, $expected);
|
$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');
|
$result = $this->Form->submit('http://example.com/cake.power.gif');
|
||||||
$expected = array(
|
$expected = array(
|
||||||
'div' => array('class' => 'submit'),
|
'div' => array('class' => 'submit'),
|
||||||
|
|
Loading…
Add table
Reference in a new issue