Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 403
robinclark007 Avatar asked Aug 12 '14 12:08

robinclark007


2 Answers

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;?>">
like image 169
SSA Avatar answered Nov 02 '22 08:11

SSA


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'];
like image 5
Steve Avatar answered Nov 02 '22 09:11

Steve