submit a disabled input in a form could not get value
Asked Answered
A

4

9

The form is like below;

<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 the $info works fine in the form.

but In the sendmail.php

$name=$_GET['name'];
$type=$_GET['textinput-disabled'];
$phone=$_GET['phone'];

I get the name and phone, but I can't get the value in the textinput-disabled. What's the problem here.

Apposition answered 12/8, 2014 at 12:36 Comment(1)
Most (all?) browsers do not send disabled fields on form submitOsculation
A
24

Disabled fields are not submitted. You can make it readonly or hidden, to get value when submitted.

<input readonly type="text" name="textinput-disabled" id="textinput-disabled" placeholder="Text input" value="<?php echo $info;?>">
Antiquate answered 12/8, 2014 at 12:38 Comment(0)
D
6

Thats expected behaviour.

Instead use

<input readonly type="text"...

Or if you must use disabled 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'];
Dishonor answered 12/8, 2014 at 12:40 Comment(2)
hidden is also a good choice.but in my situation guess it not a good one.BTW. thanks for your attention.Apposition
@Apposition which is why i suggested readonly as the most appropriate solution....Dishonor
W
0

As disabled input cannot be submitted in 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

Wrongful answered 12/8, 2014 at 12:41 Comment(0)
M
0

I had the same problem, but with a checkbox. Since the readonly value doesn't change a checkbox so that it cant be clicked, I still had to use the disable option. So I just added a hidden field with the desired variable name right below the checkbox:

<input type = 'checkbox' value = '1' name = 'EnableD_".$NR."' ";if($noti["ACTIVE"]==1)echo " checked "; echo " disabled >

<input type = 'hidden' value = '1' name = 'Enable_".$NR."' ";if($noti["ACTIVE"]==1)echo " checked "; echo " >
Metanephros answered 31/3, 2020 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.