user3004237
user3004237

Reputation: 13

HTML 5 disable attribute wont submit value to database

I have a form and if the user is logged in, fields like name and mobile number will be retrieved from their account database and also i would like to disable the inputs fields as well.

Here is the code for reference:

 <?  if ($usernamefromdatabase==$username) { ?> <input type="text" size="150" name="name" value="<? echo $givenname?>" maxlength="20" pattern="[A-Za-z\s]{1,20}" disabled> <? }
else { ?> <input type="text" size="150" name="name" value="" maxlength="20" pattern="[A-Za-z\s]{1,20}" autofocus required/> <? }  ?>

The code works and i did saw the field disabled and auto filled up. However when i have submitted, i cross checked with my database; the disabled fields did not save at all.

Can anybody shed some light?

Upvotes: 0

Views: 60

Answers (1)

Quentin
Quentin

Reputation: 943591

The point of disabled is to stop the field being submitted. Perhaps you are confusing it with readonly?

When set, the disabled attribute has the following effects on an element:

  • Disabled controls do not receive focus.
  • Disabled controls are skipped in tabbing navigation.
  • Disabled controls cannot be successful.

http://www.w3.org/TR/html4/interact/forms.html#adef-disabled

Upvotes: 3

Related Questions