Commit f93dfccd authored by Chris How's avatar Chris How

HTML::entities() now optional on label contents

parent 23d23dd0
...@@ -182,13 +182,15 @@ class Form { ...@@ -182,13 +182,15 @@ class Form {
* @param array $attributes * @param array $attributes
* @return string * @return string
*/ */
public static function label($name, $value, $attributes = array()) public static function label($name, $value, $attributes = array(), $escape_html = true)
{ {
static::$labels[] = $name; static::$labels[] = $name;
$attributes = HTML::attributes($attributes); $attributes = HTML::attributes($attributes);
if ($escape_html) {
$value = HTML::entities($value); $value = HTML::entities($value);
}
return '<label for="'.$name.'"'.$attributes.'>'.$value.'</label>'; return '<label for="'.$name.'"'.$attributes.'>'.$value.'</label>';
} }
......
...@@ -111,9 +111,11 @@ class FormTest extends PHPUnit_Framework_TestCase { ...@@ -111,9 +111,11 @@ class FormTest extends PHPUnit_Framework_TestCase {
{ {
$form1 = Form::label('foo', 'Foobar'); $form1 = Form::label('foo', 'Foobar');
$form2 = Form::label('foo', 'Foobar', array('class' => 'control-label')); $form2 = Form::label('foo', 'Foobar', array('class' => 'control-label'));
$form3 = Form::label('foo', 'Foobar <i>baz</i>', null, false);
$this->assertEquals('<label for="foo">Foobar</label>', $form1); $this->assertEquals('<label for="foo">Foobar</label>', $form1);
$this->assertEquals('<label for="foo" class="control-label">Foobar</label>', $form2); $this->assertEquals('<label for="foo" class="control-label">Foobar</label>', $form2);
$this->assertEquals('<label for="foo">Foobar <i>baz</i></label>', $form3);
} }
/** /**
......
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