mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +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'];
|
||||
unset($options['div']);
|
||||
}
|
||||
$options += array('type' => 'submit');
|
||||
$divOptions = array('tag' => 'div');
|
||||
|
||||
if ($div === true) {
|
||||
|
@ -1166,12 +1167,14 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
|
||||
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 @@ class FormHelperTest extends CakeTestCase {
|
|||
);
|
||||
$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'),
|
||||
|
|
Loading…
Add table
Reference in a new issue