Merge pull request #1676 from chrishow/form-label-html
Make HTML escaping optional for label contents.
This commit is contained in:
@@ -83,6 +83,14 @@ Laravel provides an easy method of protecting your application from cross-site r
|
|||||||
|
|
||||||
echo Form::label('email', 'E-Mail Address', array('class' => 'awesome'));
|
echo Form::label('email', 'E-Mail Address', array('class' => 'awesome'));
|
||||||
|
|
||||||
|
#### Turning off HTML escaping of label contents:
|
||||||
|
|
||||||
|
echo Form::label('confirm', 'Are you <strong>sure</strong> you want to proceed?', null, false);
|
||||||
|
|
||||||
|
You can pass ```false``` as the optional fourth argument to disable automatic HTML escaping of the label content.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
> **Note:** After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.
|
> **Note:** After creating a label, any form element you create with a name matching the label name will automatically receive an ID matching the label name as well.
|
||||||
|
|
||||||
<a name="text"></a>
|
<a name="text"></a>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
$value = HTML::entities($value);
|
if ($escape_html) {
|
||||||
|
$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 {
|
|||||||
{
|
{
|
||||||
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user