Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value from disabled text input field doesn't pass POST method on form

Status
Not open for further replies.

alfalf

Programmer
Mar 6, 2003
155
BA
Hello all.

It seems that value from disabled text input field doesn't pass POST method.

Can that be a case?

I use PHP as SSS, and it returns unset value of HTML disabled field on POST method HTML form, even if it value is set.

Help? Thanks.
 
You are correct. Forms do not pass the values of disabled fields through. If you want the value, the field has to be enabled.

Having said that, read-only fields DO pass their value through, so that may be a way around your problem. Or, if you do not mind using JavaScript, you could copy the value of the disabled field into a hidden field onsubmit.

Hope this helps,
Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks. I used read-only already, it smelled on something like that :). Thanks.
 
copy the value of the disabled field into a hidden field onsubmit

There's really no need to do that. If you're using javascript, just enable the fields that were disabled before you submit the form. If they're enabled, there values will be passed.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
I thought about that, then thought there would be more potential for "fiddling" by users who stopped the submission after the fields were enabled.

Then again, thinking about it, any user with a DOM inspector can modify the states... so I guess my safety-concious answer wasn't necessary after all ;o)

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
If the status of the field in question is disabled when you send the form, and can't be changed by the user, you could put a hidden field in the original form:
Code:
<!-- display username field to user, they can't change it -->
<input name="username2" value="fred" disabled="disabled" />
<!-- The real value is hidden -->
<input type="hidden" name="username" value="fred">
This removes the Javascript dependency in such cases.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
i'm not sure why you are wanting to disable the field (i guess you could be enabling or disabling the field at some point in the life of the page with javascript). but if it is not neccesary that the value/string be displayed in a text field, you could display the value just as text and store the value in a session variable instead of a form field.

not sure of your situation, but just a suggestion.

-Jer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top