开发者

Allow html in input default value

Just a quick question..

I am trying to generate an text input where the default value is nested in tag with an inline css..just to make it look smaller and grayer than the normal input.

echo $this->Form->input( 'address', array('div'=>false, 'label'=>'', 'default'=>'<span style="font-size: 0.6em;color:#e3e3e3;">put your address here</span>', 'size'=>'50' ) );

after the user would click, the default value would be erased leaving it blank.

However cakephp generates the input with the value containing the html tags, i.e. . How do I make cakephp unfilter 开发者_开发问答the html in the default value?

I forgot what option to use in this situation and I tried everything that I can think of. I remember that I can do this by just adding some sort of value in the option array like 'html'=>false.


Put your helper text in your labels. If you put the default value as a HTML string the Input will display the HTML as it does not render HTML inside of it.

If you add the additional HTML to your label, you could use this http://trevordavis.net/blog/jquery-inline-form-labels to overlay the labels over the inputs.

echo $this->Form->input( 'address', array('div'=>false, 'label'=>'put your address here','size'=>'50' ) );

Also, this method allows you to apply the css externally instead of inline -- which is always best.


I am not aware of any way to get an input box to render html inside itself. There is also nothing in the API to suggest what you want. It is possible to embed it within a div, and to include things before, after, and between the label and input. I think you need to use javascript to accomplish what you want to do.

<style>
.default {font-size: 0.6em;color:#e3e3e3;}
.normal {color:black;}
</style>
<script language='javascript'>
function change(input)
{
    input.classList.add("normal");
    if (input.value == "enter text here")
        input.value = "";
}
</script>
<form>
<input id='test' class='default' type='text' value='enter text here' onfocus='change(this);'>
</form>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜