robinclark007
robinclark007

Reputation: 151

submit a disabled input in a form could not get value

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.

Upvotes: 9

Views: 30861

Answers (4)

Leendert
Leendert

Reputation: 119

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 " >

Upvotes: 0

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28523

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

Upvotes: 0

Steve
Steve

Reputation: 20469

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'];

Upvotes: 6

SSA
SSA

Reputation: 5483

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;?>">

Upvotes: 25

Related Questions