简体   繁体   中英

How to make Laravel (Blade) text field readonly

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:

{{ 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:

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

Cheers.

For Laravel 5 and above

{!! 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.

<input class="class-name" readonly="readonly" name="name" type="text" value="default-value">

For Laravel < 5 , this should work

{{ 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:

{!! BootForm::text('Name', 'name', $name)->disable() !!}

Based on the docs of adamwathan/form . Hope it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM