PHP disabled form field values are missing

16th June, 2009 - 1 minute read

Never forget that a disabled form field value will not be passed in PHP when posted. Consider the following:

<form action=’ ‘ method=’post’>
<input type=’text’ name=’enabledField’ value=’value_1′ />
<input type=’text’ name=’disabledField’ value=’value_2′ disabled />

When this form is posted retrieving the two fields will return as follows:

<?php echo $_POST[enabledField]?> returns value_1
<?php echo $_POST[disabledField]?> returns nothing

This is always worth remembering to save you time trying to work out why your post values are not being passed. Of course they are ways around this e.g. duplicating the field with a hidden text field, or simply not disabling the field in the first place.