[英]How to make Laravel (Blade) text field readonly
I have a text box that needs to be made readonly
; 我有一个需要
readonly
的文本框; I don't want to use array('disabled' => 'true')
because I need PHP to process the field: 我不想使用
array('disabled' => 'true')
因为我需要PHP来处理字段:
{{ Form::text('login_token', Worker::generateLoginToken()) }}
How do you add this attribute? 你如何添加这个属性?
只需将其添加为第3个参数:
{{ Form::text('login_token', Worker::generateLoginToken(), ['readonly']) }}
That's how I did it in Laravel 5: 这就是我在Laravel 5中的表现:
{!! Form::text('id', null, ['class' => 'form-control', 'readonly' => 'true']) !!}
Cheers. 干杯。
For Laravel 5 and above 对于Laravel 5及以上版本
{!! Form::text('name', 'default-value', ['class'=>'class-name','readonly']) !!}
In third argument you can pass all your extra arguments in form of an array. 在第三个参数中,您可以以数组的形式传递所有额外的参数。 This line will result into something like this in html.
这行将在html中产生类似的结果。
<input class="class-name" readonly="readonly" name="name" type="text" value="default-value">
For Laravel < 5 , this should work 对于Laravel <5,这应该有效
{{ Form::text('name', 'default-value', ['class'=>'class-name','readonly']) }}
写下以下行
{!! Form::text('field_name','field_value',array('class'=>'form-control','readonly')) !!}
试试这个...
{{ Form::text('login_token', Worker::generateLoginToken(),array('readonly')) }}
I am using Laravel 5.4 along with BootForm, and the only way that it has worked was by doing: 我正在使用Laravel 5.4和BootForm,它的唯一工作方式是:
{!! BootForm::text('Name', 'name', $name)->disable() !!}
Based on the docs of adamwathan/form . 基于adamwathan / form的文档。 Hope it helps!
希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.