mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Implementing FormHelper::button(), with options for alternate button types (Ticket #2341)
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6188 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
e6af521843
commit
5e7f3a8287
3 changed files with 35 additions and 20 deletions
|
@ -891,33 +891,23 @@ class FormHelper extends AppHelper {
|
|||
/**
|
||||
* Creates a button tag.
|
||||
*
|
||||
* @param mixed $params Array of params [content, type, options] or the
|
||||
* content of the button.
|
||||
* @param string $type Type of the button (button, submit or reset).
|
||||
* @param string $title The button's caption
|
||||
* @param array $options Array of options.
|
||||
* @return string A HTML button tag.
|
||||
* @access public
|
||||
*/
|
||||
function button($params, $type = 'button', $options = array()) {
|
||||
function button($title, $options = array()) {
|
||||
$options = array_merge(array('type' => 'button', 'value' => $title), $options);
|
||||
|
||||
trigger_error(__("Don't use me yet"), E_USER_ERROR);
|
||||
if (isset($options['name'])) {
|
||||
if (strpos($options['name'], "/") !== false || strpos($options['name'], ".") !== false) {
|
||||
if ($this->value($options['name'])) {
|
||||
$options['checked'] = 'checked';
|
||||
}
|
||||
$this->setFieldName($options['name']);
|
||||
$options['name'] = 'data[' . $this->model() . '][' . $this->field() . ']';
|
||||
if (isset($options['name']) && (strpos($options['name'], "/") !== false || strpos($options['name'], ".") !== false)) {
|
||||
if ($this->value($options['name'])) {
|
||||
$options['checked'] = 'checked';
|
||||
}
|
||||
$name = $options['name'];
|
||||
unset($options['name']);
|
||||
$options = $this->__initInputField($name, $options);
|
||||
}
|
||||
|
||||
$options['type'] = $type;
|
||||
|
||||
$values = array(
|
||||
'options' => $this->_parseOptions($options),
|
||||
'tagValue' => $content
|
||||
);
|
||||
return $this->_assign('button', $values);
|
||||
return $this->output(sprintf($this->Html->tags['button'], $options['type'], $this->_parseAttributes($options, array('type'), '', ' ')));
|
||||
}
|
||||
/**
|
||||
* Creates a submit button element.
|
||||
|
|
|
@ -69,6 +69,7 @@ class HtmlHelper extends AppHelper {
|
|||
'file_no_model' => '<input type="file" name="%s" %s/>',
|
||||
'submit' => '<input type="submit" %s/>',
|
||||
'submitimage' => '<input type="image" src="%s" %s/>',
|
||||
'button' => '<input type="%s" %s/>',
|
||||
'image' => '<img src="%s" %s/>',
|
||||
'tableheader' => '<th%s>%s</th>',
|
||||
'tableheaderrow' => '<tr%s>%s</tr>',
|
||||
|
|
|
@ -1153,6 +1153,30 @@ class FormHelperTest extends CakeTestCase {
|
|||
$this->assertNoPattern('/<input[^<>]+[^(type|name|value|id)]=[^<>]*>$/', $result);
|
||||
}
|
||||
|
||||
function testButton() {
|
||||
$result = $this->Form->button('Hi');
|
||||
$expected = '<input type="button" value="Hi" />';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Form->button('Clear Form', array('type' => 'clear'));
|
||||
$expected = '<input type="clear" value="Clear Form" />';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Form->button('Reset Form', array('type' => 'reset'));
|
||||
$expected = '<input type="reset" value="Reset Form" />';
|
||||
$this->assertEqual($result, $expected);
|
||||
|
||||
$result = $this->Form->button('Options', array('type' => 'reset', 'name' => 'Post.options'));
|
||||
$this->assertPattern('/^<input type="reset" [^<>]+ \/>$/', $result);
|
||||
$this->assertPattern('/^<input [^<>]+value="Options"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input [^<>]+name="data\[Post\]\[options\]"[^<>]+\/>$/', $result);
|
||||
$this->assertPattern('/^<input [^<>]+id="PostOptions"[^<>]+\/>$/', $result);
|
||||
|
||||
$result = $this->Form->button('Options', array('type' => 'reset', 'name' => 'Post.options', 'id' => 'Opt'));
|
||||
$this->assertPattern('/^<input [^<>]+id="Opt"[^<>]+\/>$/', $result);
|
||||
$this->assertNoPattern('/^<input [^<>]+id=[^<>]+id=/', $result);
|
||||
}
|
||||
|
||||
function testSubmitButton() {
|
||||
$result = $this->Form->submit('Test Submit');
|
||||
$this->assertPattern('/^<div\s+class="submit"><input type="submit"[^<>]+value="Test Submit"[^<>]+\/><\/div>$/', $result);
|
||||
|
|
Loading…
Add table
Reference in a new issue