php 如何使 Laravel (Blade) 文本字段只读

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28955136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 00:10:05  来源:igfitidea点击:

How to make Laravel (Blade) text field readonly

phphtmllaravelblade

提问by Marcel

I have a text box that needs to be made readonly; I don't want to use array('disabled' => 'true')because I need PHP to process the field:

我有一个需要制作的文本框readonly;我不想使用,array('disabled' => 'true')因为我需要 PHP 来处理该字段:

{{ Form::text('login_token', Worker::generateLoginToken()) }}

How do you add this attribute?

你如何添加这个属性?

回答by Joseph Silber

Just add it as the 3rd argument:

只需将其添加为第三个参数:

{{ Form::text('login_token', Worker::generateLoginToken(), ['readonly']) }}

回答by Shoaib Raza

That's how I did it in Laravel 5:

这就是我在 Laravel 5 中的做法:

{!! Form::text('id', null, ['class' => 'form-control', 'readonly' => 'true']) !!}

Cheers.

干杯。

回答by Yogendra

Write the following line

写下一行

{!! Form::text('field_name','field_value',array('class'=>'form-control','readonly')) !!}

回答by Yogesh Yadav

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']) }}

回答by facundofarias

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. Hope it helps!

基于adamwathan/form的文档。希望能帮助到你!

回答by Deenadhayalan Manoharan

Try this...

尝试这个...

{{ Form::text('login_token', Worker::generateLoginToken(),array('readonly')) }}