mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Changing FormHelper::button() to actually create <button> elements instead of input elements. Test cases added.
This commit is contained in:
parent
08f07a9aa4
commit
fa6b1b1a20
3 changed files with 18 additions and 25 deletions
|
@ -1107,28 +1107,27 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a button tag.
|
||||
* Creates a <button> tag.
|
||||
*
|
||||
* @param string $title The button's caption
|
||||
* @param array $options Array of options.
|
||||
* Options:
|
||||
*
|
||||
* - `escape` - HTML entity encode the $title of the button. Defaults to false.
|
||||
*
|
||||
* @param string $title The button's caption. Not automatically HTML encoded
|
||||
* @param array $options Array of options and HTML attributes.
|
||||
* @return string A HTML button tag.
|
||||
* @access public
|
||||
*/
|
||||
function button($title, $options = array()) {
|
||||
$options = array_merge(array('type' => 'button', 'value' => $title), $options);
|
||||
|
||||
if (isset($options['name']) && strpos($options['name'], '.') !== false) {
|
||||
if ($this->value($options['name'])) {
|
||||
$options['checked'] = 'checked';
|
||||
}
|
||||
$name = $options['name'];
|
||||
unset($options['name']);
|
||||
$options = $this->_initInputField($name, $options);
|
||||
$options += array('type' => 'submit', 'escape' => false);
|
||||
if ($options['escape']) {
|
||||
$title = h($title);
|
||||
}
|
||||
return $this->output(sprintf(
|
||||
$this->Html->tags['button'],
|
||||
$options['type'],
|
||||
$this->_parseAttributes($options, array('type'), '', ' ')
|
||||
$this->_parseAttributes($options, array('type'), '', ' '),
|
||||
$title
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ class HtmlHelper extends AppHelper {
|
|||
'file_no_model' => '<input type="file" name="%s" %s/>',
|
||||
'submit' => '<input %s/>',
|
||||
'submitimage' => '<input type="image" src="%s" %s/>',
|
||||
'button' => '<input type="%s" %s/>',
|
||||
'button' => '<button type="%s"%s>%s</button>',
|
||||
'image' => '<img src="%s" %s/>',
|
||||
'tableheader' => '<th%s>%s</th>',
|
||||
'tableheaderrow' => '<tr%s>%s</tr>',
|
||||
|
|
|
@ -4491,19 +4491,13 @@ class FormHelperTest extends CakeTestCase {
|
|||
*/
|
||||
function testButton() {
|
||||
$result = $this->Form->button('Hi');
|
||||
$this->assertTags($result, array('input' => array('type' => 'button', 'value' => 'Hi')));
|
||||
$this->assertTags($result, array('button' => array('type' => 'submit'), 'Hi', '/button'));
|
||||
|
||||
$result = $this->Form->button('Clear Form', array('type' => 'clear'));
|
||||
$this->assertTags($result, array('input' => array('type' => 'clear', 'value' => 'Clear Form')));
|
||||
$result = $this->Form->button('Clear Form >', array('type' => 'reset'));
|
||||
$this->assertTags($result, array('button' => array('type' => 'reset'), 'Clear Form >', '/button'));
|
||||
|
||||
$result = $this->Form->button('Reset Form', array('type' => 'reset'));
|
||||
$this->assertTags($result, array('input' => array('type' => 'reset', 'value' => 'Reset Form')));
|
||||
|
||||
$result = $this->Form->button('Options', array('type' => 'reset', 'name' => 'Post.options'));
|
||||
$this->assertTags($result, array('input' => array('type' => 'reset', 'name' => 'data[Post][options]', 'id' => 'PostOptions', 'value' => 'Options')));
|
||||
|
||||
$result = $this->Form->button('Options', array('type' => 'reset', 'name' => 'Post.options', 'id' => 'Opt'));
|
||||
$this->assertTags($result, array('input' => array('type' => 'reset', 'name' => 'data[Post][options]', 'id' => 'Opt', 'value' => 'Options')));
|
||||
$result = $this->Form->button('<Clear Form>', array('type' => 'reset', 'escape' => true));
|
||||
$this->assertTags($result, array('button' => array('type' => 'reset'), '<Clear Form>', '/button'));
|
||||
|
||||
$result = $this->Form->button('Upload Text', array('onClick' => "$('#postAddForm').ajaxSubmit({target: '#postTextUpload', url: '/posts/text'});return false;'", 'escape' => false));
|
||||
$this->assertNoPattern('/\&039/', $result);
|
||||
|
|
Loading…
Add table
Reference in a new issue