Using HTML Placeholder in Laravel 4

时光怂恿深爱的人放手 提交于 2020-11-26 07:18:11

问题


{{ Form::text('username', Input::old('username')) }}

This is my code, I want to add Username as placeholder in the text box. I already use bootstrap in the project.

I tried to use the example

{{ Form::text('username', 'Username', Input::old('username')) }}

But it gives a default value which needs to be deleted and then the user has to type his value. I want something like how it shows up on Twitter.com etc. Which gets erased once user types into it.


回答1:


{{ Form::text('username', Input::old('username'),  array('placeholder'=>'Username')) }}

This works for Laravel 4!!




回答2:


{{ Form::text('username', null, array('placeholder'=>'Username' )); }}



回答3:


Use:

{{ Form::text('txtUsername', '',array('class'=>'input', 'placeholder'=>'Username')) }}



回答4:


Been a while since this was updated but with Former for Laravel the way to do this would be:

Former::text('field')->placeholder('langfile.path.to.placeholder.text')))

The lang file would be called langfile.php with the array containing:

<?php

    return array (  
        'path.to.placeholder.text' => 'Some Placeholder Text.'
    );



回答5:


In case somebody wonders how this should work for a password field:

{{ Form::password('password',  array('placeholder'=>'Password')) }}


来源:https://stackoverflow.com/questions/17387178/using-html-placeholder-in-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!