2013-06-30 72 views
15
{{ Form::text('username', Input::old('username')) }} 

這是我的代碼,我想在文本框中添加用戶名作爲佔位符。我已經在項目中使用bootstrap了。在Laravel中使用HTML佔位符4

我試圖用的例子

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

但它給需要被刪除,然後用戶必須鍵入他的價值的默認值。我想要的東西就像它在Twitter.com上顯示的一樣,一旦用戶輸入,就會被刪除。

+0

+1的輸入::舊的(),從來不知道,到現在爲止。 –

回答

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

這適用於Laravel 4!

+0

標記爲答案。 – ranisalt

+2

您可能想要使用的密碼字段'{{Form :: password('field-name',array('placeholder'=>'placeholder text','class'=>'class-name')}}'hope它有幫助! –

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

這實際上是一個可行的答案,因爲它刪除並用短而簡潔的代碼取代不必要的參數。這應該是正確的答案,因爲該問題只需要添加placeholdes以形成laravel 4元素的方式。我重申,這是正確的答案 –

1

已經有一段時間,因爲這是更新,但與前爲Laravel做的方式,這將是:

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

朗文件將被稱爲包含數組langfile.php:

<?php 

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

如果有人想知道應如何輸入密碼領域的工作:

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

用途:

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