Commit 11c14a20 by Qiang Xue

Simplified button signature.

parent 9a5ca995
......@@ -22,6 +22,6 @@ $this->params['breadcrumbs'][] = $this->title;
<?php echo $form->field('password')->passwordInput(); ?>
<?php echo $form->field('rememberMe')->checkbox(); ?>
<div class="form-actions">
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?>
<?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
</div>
<?php ActiveForm::end(); ?>
......@@ -36,6 +36,6 @@ $this->params['breadcrumbs'][] = $this->title;
'options' => array('class' => 'input-medium'),
)); ?>
<div class="form-actions">
<?php echo Html::submitButton('Submit', null, null, array('class' => 'btn btn-primary')); ?>
<?php echo Html::submitButton('Submit', array('class' => 'btn btn-primary')); ?>
</div>
<?php ActiveForm::end(); ?>
......@@ -22,6 +22,6 @@ $this->params['breadcrumbs'][] = $this->title;
<?php echo $form->field('password')->passwordInput(); ?>
<?php echo $form->field('rememberMe')->checkbox(); ?>
<div class="form-actions">
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?>
<?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
</div>
<?php ActiveForm::end(); ?>
......@@ -36,6 +36,6 @@ $this->params['breadcrumbs'][] = $this->title;
'options' => array('class' => 'input-medium'),
)); ?>
<div class="form-actions">
<?php echo Html::submitButton('Submit', null, null, array('class' => 'btn btn-primary')); ?>
<?php echo Html::submitButton('Submit', array('class' => 'btn btn-primary')); ?>
</div>
<?php ActiveForm::end(); ?>
......@@ -22,6 +22,6 @@ $this->params['breadcrumbs'][] = $this->title;
<?php echo $form->field('password')->passwordInput(); ?>
<?php echo $form->field('rememberMe')->checkbox(); ?>
<div class="form-actions">
<?php echo Html::submitButton('Login', null, null, array('class' => 'btn btn-primary')); ?>
<?php echo Html::submitButton('Login', array('class' => 'btn btn-primary')); ?>
</div>
<?php ActiveForm::end(); ?>
......@@ -421,18 +421,14 @@ class Html
* @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded.
* Therefore you can pass in HTML code such as an image tag. If this is is coming from end users,
* you should consider [[encode()]] it to prevent XSS attacks.
* @param string $name the name attribute. If it is null, the name attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* If the options does not contain "type", a "type" attribute with value "button" will be rendered.
* @return string the generated button tag
*/
public static function button($content = 'Button', $name = null, $value = null, $options = array())
public static function button($content = 'Button', $options = array())
{
$options['name'] = $name;
$options['value'] = $value;
if (!isset($options['type'])) {
$options['type'] = 'button';
}
......@@ -444,17 +440,15 @@ class Html
* @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded.
* Therefore you can pass in HTML code such as an image tag. If this is is coming from end users,
* you should consider [[encode()]] it to prevent XSS attacks.
* @param string $name the name attribute. If it is null, the name attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* @return string the generated submit button tag
*/
public static function submitButton($content = 'Submit', $name = null, $value = null, $options = array())
public static function submitButton($content = 'Submit', $options = array())
{
$options['type'] = 'submit';
return static::button($content, $name, $value, $options);
return static::button($content, $options);
}
/**
......@@ -462,17 +456,15 @@ class Html
* @param string $content the content enclosed within the button tag. It will NOT be HTML-encoded.
* Therefore you can pass in HTML code such as an image tag. If this is is coming from end users,
* you should consider [[encode()]] it to prevent XSS attacks.
* @param string $name the name attribute. If it is null, the name attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* @return string the generated reset button tag
*/
public static function resetButton($content = 'Reset', $name = null, $value = null, $options = array())
public static function resetButton($content = 'Reset', $options = array())
{
$options['type'] = 'reset';
return static::button($content, $name, $value, $options);
return static::button($content, $options);
}
/**
......@@ -495,43 +487,46 @@ class Html
/**
* Generates an input button.
* @param string $name the name attribute.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param string $label the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* @return string the generated button tag
*/
public static function buttonInput($name, $value = 'Button', $options = array())
public static function buttonInput($label = 'Button', $options = array())
{
return static::input('button', $name, $value, $options);
$options['type'] = 'button';
$options['value'] = $label;
return static::tag('input', null, $options);
}
/**
* Generates a submit input button.
* @param string $name the name attribute. If it is null, the name attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param string $label the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the tag options in terms of name-value pairs. These will be rendered as
* the attributes of the resulting tag. The values will be HTML-encoded using [[encode()]].
* If a value is null, the corresponding attribute will not be rendered.
* @return string the generated button tag
*/
public static function submitInput($name = null, $value = 'Submit', $options = array())
public static function submitInput($label = 'Submit', $options = array())
{
return static::input('submit', $name, $value, $options);
$options['type'] = 'submit';
$options['value'] = $label;
return static::tag('input', null, $options);
}
/**
* Generates a reset input button.
* @param string $name the name attribute. If it is null, the name attribute will not be generated.
* @param string $value the value attribute. If it is null, the value attribute will not be generated.
* @param string $label the value attribute. If it is null, the value attribute will not be generated.
* @param array $options the attributes of the button tag. The values will be HTML-encoded using [[encode()]].
* Attributes whose value is null will be ignored and not put in the tag returned.
* @return string the generated button tag
*/
public static function resetInput($name = null, $value = 'Reset', $options = array())
public static function resetInput($label = 'Reset', $options = array())
{
return static::input('reset', $name, $value, $options);
$options['type'] = 'reset';
$options['value'] = $label;
return static::tag('input', null, $options);
}
/**
......
......@@ -154,20 +154,20 @@ class HtmlTest extends TestCase
public function testButton()
{
$this->assertEquals('<button type="button">Button</button>', Html::button());
$this->assertEquals('<button type="button" name="test" value="value">content<></button>', Html::button('content<>', 'test', 'value'));
$this->assertEquals('<button type="submit" class="t" name="test" value="value">content<></button>', Html::button('content<>', 'test', 'value', array('type' => 'submit', 'class' => "t")));
$this->assertEquals('<button type="button" name="test" value="value">content<></button>', Html::button('content<>', array('name' => 'test', 'value' => 'value')));
$this->assertEquals('<button type="submit" class="t" name="test" value="value">content<></button>', Html::button('content<>', array('type' => 'submit', 'name' => 'test', 'value' => 'value', 'class' => "t")));
}
public function testSubmitButton()
{
$this->assertEquals('<button type="submit">Submit</button>', Html::submitButton());
$this->assertEquals('<button type="submit" class="t" name="test" value="value">content<></button>', Html::submitButton('content<>', 'test', 'value', array('class' => 't')));
$this->assertEquals('<button type="submit" class="t" name="test" value="value">content<></button>', Html::submitButton('content<>', array('name' => 'test', 'value' => 'value', 'class' => 't')));
}
public function testResetButton()
{
$this->assertEquals('<button type="reset">Reset</button>', Html::resetButton());
$this->assertEquals('<button type="reset" class="t" name="test" value="value">content<></button>', Html::resetButton('content<>', 'test', 'value', array('class' => 't')));
$this->assertEquals('<button type="reset" class="t" name="test" value="value">content<></button>', Html::resetButton('content<>', array('name' => 'test', 'value' => 'value', 'class' => 't')));
}
public function testInput()
......@@ -178,20 +178,20 @@ class HtmlTest extends TestCase
public function testButtonInput()
{
$this->assertEquals('<input type="button" name="test" value="Button" />', Html::buttonInput('test'));
$this->assertEquals('<input type="button" class="a" name="test" value="text" />', Html::buttonInput('test', 'text', array('class' => 'a')));
$this->assertEquals('<input type="button" value="Button" />', Html::buttonInput());
$this->assertEquals('<input type="button" class="a" name="test" value="text" />', Html::buttonInput('text', array('name' => 'test', 'class' => 'a')));
}
public function testSubmitInput()
{
$this->assertEquals('<input type="submit" value="Submit" />', Html::submitInput());
$this->assertEquals('<input type="submit" class="a" name="test" value="text" />', Html::submitInput('test', 'text', array('class' => 'a')));
$this->assertEquals('<input type="submit" class="a" name="test" value="text" />', Html::submitInput('text', array('name' => 'test', 'class' => 'a')));
}
public function testResetInput()
{
$this->assertEquals('<input type="reset" value="Reset" />', Html::resetInput());
$this->assertEquals('<input type="reset" class="a" name="test" value="text" />', Html::resetInput('test', 'text', array('class' => 'a')));
$this->assertEquals('<input type="reset" class="a" name="test" value="text" />', Html::resetInput('text', array('name' => 'test', 'class' => 'a')));
}
public function testTextInput()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment