Submit disabled form input failed to get value
The form looks like this:
<form action="sendmail.php" method="get">
<input type="text" name="phone" id="phone" data-clear-btn="true">
<input type="text" name="name" id="name" data-clear-btn="true">
<input disabled="disabled" type="text" name="textinput-disabled" id="textinput-disabled" placeholder="Text input" value="<?php echo $info;?>">
</form>
$ info = "type1"; and $ info works fine on the form.
but in sendmail.php
$name=$_GET['name'];
$type=$_GET['textinput-disabled'];
$phone=$_GET['phone'];
I am getting name and phone number, but I can’t get the value in textinput-disabled. What is the problem here.
+3
source to share
3 answers
Expected behavior.
Use instead
<input readonly type="text"...
Or, if you must disconnect for some reason, add a hidden field:
<input disabled="disabled" type="text" name="textinput-disabled" id="textinput-disabled" placeholder="Text input" value="<?php echo $info;?>">
<input type="hidden" name="hidden" value="<?php echo $info;?>">
$name=$_GET['name'];
$type=$_GET['hidden'];
$phone=$_GET['phone'];
0
source to share
Since the disabled input
cannot be submitted in the form, so you can use readonly="readonly"
, so use below:
<input readonly="readonly" type="text"
name="textinput-disabled" id="textinput-disabled"
placeholder="Text input" value="<?php echo $info;?>">
For more information on readonly
0
source to share