Saving readonly fields to database?

KMonsefi 03 Nov, 2009
Hi,

When creating a table for a form that contains readonly fields, the readonly fields do NOT show up as database fields. I tried adding them manually, naming the fields in the database the same as they are on the form, but the values are NOT being saved. How can I save readonly fields to the database?

Thanks.
GreyHead 03 Nov, 2009
Hi Kmonsefi,

Basically you can't - readonly field values aren't included in the $_POST arry that is sent back to the server.

You can use disabled fields, or you can put the values of the readonly fields into hidden fields with the same name - those will be saved.

Bob
KMonsefi 03 Nov, 2009
Disabled fields don't seem to work either. How would you suggest using hidden fields to accomplish this?
GreyHead 04 Nov, 2009
Hi Kmonsefi,

Oops yes, I was wrong. Disabled fields are worse than readonly.

If you put the value in a hidden field that it will be returned and saved, not sure what else there is to say about that.

What are you trying to do with the readonly fields here?

Bob
KMonsefi 04 Nov, 2009
If users are logged in, I'm prepopulating the name and email fields for my forms. Since these fields should not be changeable when logged in, I'm making them readonly.

Regarding using hidden fields, would my code look like this?

<input id="Name" maxlength="50" size="30" name="Name" value="Logged In Name" readonly />
<input id="Name" maxlength="50" size="30" name="Name" value="Logged In Name" type="hidden" />
KMonsefi 04 Nov, 2009
Yes, that seemed to work!

Thanks!
GreyHead 04 Nov, 2009
Hi KMonsefi,

Perfect.

Bob
This topic is locked and no more replies can be posted.