How do I post disabled input
use the attribute readonly
instead of disabled
.
- readonly: input can't be modified
- disabled: input has no form function
- (and the related third option: input type=hidden: input is not visible, but the value is submitted)
you get an error because an disabled element is not sent when the form is submitted and thus is not present in $_POST
(there simply is no $_POST['client1']
in your case)
edit edited: the examples were not complete - as the accepted answer states, the name
attribute must be present, too
<input type="text" name="client1" class = "client" size="12" id ="client1" value="something" readonly />
or
<input type="text" name="client1" class = "client" size="12" id ="client1" value="something" readonly="readonly" />
if you want to have a more xml-like syntax.
Here is an idea of how you can solve this
<form action = 'insert.php' method="post" >
<input type="text" name="client1" class="client" size="12" id="client1" disabled />
<input hidden name="client1" value="inserted_value_of_client1"/>
</form>
You can even remove name from the first input.
With this, your disabled input will still be displayed but php will post the value in your hidden input field.
You can use
<?php echo !empty($text)?$text:'';?>
to populate the value
fields as shown in some answers here
TLDR;
<form action="index.php" method="post">
<input type="text" disabled value="my_value"/>
<input hidden name="client" value="my_value"/>
</form>