Welcome Guest, Not a member yet? Register   Sign In
Form helper Readonly
#1

[eluser]jimbo_jones[/eluser]
Hi all,

Looking for a way to have a form input field be READONLY when using the form helper.

Is there anyway to do this or do I need to use my own "helper"

jimbo
#2

[eluser]imzyos[/eluser]
well maybe..

Disables the input element when it first loads so that the user can not write text in it, or select it.

Note: Cannot be used with type="hidden"

Code:
<INPUT NAME="realname" VALUE="Hi There" READONLY>
<INPUT NAME="realname" VALUE="Hi There" DISABLED>
#3

[eluser]ballen[/eluser]
Try something like...

Code:
$data = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => 'johndoe',
              'maxlength'   => '100',
              'size'        => '50',
              'style'       => 'width:50%',
              'readonly'    => 'readonly'
            );

echo form_input($data);
#4

[eluser]jimbo_jones[/eluser]
Thanks for the tips,

It turns out they both work, albeit with slightly different results.

Using
Code:
'disabled'=>'diabled'

Does indeed render the field READONLY, but it also greys out the input field.

using
Code:
'readonly'=>'readonly'

Also renders the field READONLY, but does not change the background color of the input field.

There may be some stylesheet stuff that is happening here that distinguishes the two, but the difference is interesting.

Either way, I've go what I need. Thank you both! :-D

jimbo
#5

[eluser]ballen[/eluser]
I think its just browser default styling, and prbably varies browser to browser.

The real difference between the two is (as taken from W3Schools)

Disabled
Disables the input element when it first loads so that the user can not write text in it, or select it. (Note: Cannot be used with type="hidden")

Read Only
Indicates that the value of this field cannot be modified. (Note: Only used with type="text")
#6

[eluser]Michael Wales[/eluser]
Yeah, the difference is disabled is a temporary read only, that you can then reverse via Javascript to enable it. Whereas read only should be just that, always, read only.
#7

[eluser]jimbo_jones[/eluser]
walesmd -

Ah. Thanks for the clarification.

jimbo




Theme © iAndrew 2016 - Forum software by © MyBB