问题
{{ 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