Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable input field without affecting the value of the field in a PHP form?

Tags:

html

php

I'm creating a demo page where certain setting fields have to be disabled. I have tried disabling the input with the value remaining intact, just greyed out. I have disabled the inputs using disabled="true". When submitting the form, the value disappears in spite of being there before. How do I prevent the value from disappearing whilst simultaneously disabling the said fields?

like image 988
Daphne Avatar asked Dec 22 '22 00:12

Daphne


2 Answers

If you want the value to be displayed and and not changed , you can use readonly

<input type="text" name="xxx" value="xxx" readonly="readonly" />

If you want the value to be hidden and submitted to the action file you can use type =hidden

<input type="hidden" name="xxxx" value="xxx" /> 

More about HTML input tag can be found here http://www.w3schools.com/tags/tag_input.asp

like image 200
Kamal Saleh Avatar answered Dec 24 '22 03:12

Kamal Saleh


disabled form fields are not submitted under any circumstances.

The most common way to avoid this problem is making them readonly and adding an input[readonly] { ... } css rule to make the text gray like in a disabled field.

You might also want to use some JavaScript to prevent it from being focused; could look like this if you have jQuery:

$('input[readonly]').live('focus', function(e) {
    $(this).blur();
});
like image 24
ThiefMaster Avatar answered Dec 24 '22 02:12

ThiefMaster