How to make Laravel (Blade) text field readonly
Asked Answered
P

7

22

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?

Prefabricate answered 10/3, 2015 at 2:23 Comment(0)
H
40

Just add it as the 3rd argument:

{{ Form::text('login_token', Worker::generateLoginToken(), ['readonly']) }}
Hillegass answered 10/3, 2015 at 2:24 Comment(1)
Both this and the answer by @Jocker produce the same results. Both work. Thanks!Prefabricate
A
22

That's how I did it in Laravel 5:

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

Cheers.

Atingle answered 15/10, 2015 at 1:20 Comment(0)
L
4

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']) }}
Laclos answered 8/6, 2016 at 0:58 Comment(0)
C
4

Write the following line

{!! Form::text('field_name','field_value',array('class'=>'form-control','readonly')) !!}
Crofter answered 13/3, 2018 at 10:24 Comment(0)
P
0

Try this...

{{ Form::text('login_token', Worker::generateLoginToken(),array('readonly')) }}
Pretence answered 10/3, 2015 at 3:54 Comment(1)
If you could please explain what the code you're showing does, and why/how that code answers the question, it would make your answer even more helpful.Allegiance
D
0

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!

Duralumin answered 20/7, 2017 at 10:35 Comment(0)
P
0

U can try...

'attr' => ['readonly']

Example:

$this->add('created_at', 'text', [
    'label' => 'Data do contato',
    'value' => $this->model->created_at->format('d/m/Y H:i:s'),
    'attr' => ['readonly']
]);
Pelson answered 25/9, 2023 at 21:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.