Disabled HTML textbox not posting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Disabled HTML textbox not posting

Post by impulse() »

I've been crawling through code to find an error which turned out to be a disabled text box not posting its data. Surely there's a way to make it post data? This is a simple script I used to test if it works, but it doesn't:

Code: Select all

<
form method = 'post'>
  <input type = 'text' name = 'disabledBox' value = 'Filled in disabled box' disabled>
  <input type = 'text' name = 'enabledBox'>
  <input type = 'submit' value = 'Shoot'>
</form>

<?php

if($_POST)
  print_r($_POST); 

?>
But this only posts the data from the text box that's enabled.

Regards,
mcog_esteban
Forum Contributor
Posts: 127
Joined: Tue Dec 30, 2003 3:28 pm

Post by mcog_esteban »

try instead of disabled: readonly
Steve Mellor
Forum Commoner
Posts: 49
Joined: Thu Aug 02, 2007 8:18 am

Post by Steve Mellor »

Or, if the user doesn't need to see the input, use a hidden field.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you need to enable the field if you want it to post - might I suggest a snippit of jQuery to re-enable all fields on submit?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

The readonly attribute worked a treat.


Thanks.
Post Reply