How do I post disabled input

Thephpdoge picture Thephpdoge · Apr 10, 2014 · Viewed 52.9k times · Source

Hello I have some input but one of them is disabled ( yes and i need it for my time sheet )but how do I send it autocomplete.php to insert.php I've this error Undefined index: client1 in C:\wamp\www\testlp\insert.php on line 30

Here my code autocomplete.php

<form action = 'insert.php' method="post"  >

    <input type="text" name="client1" class = "client" size="12" id ="client1" disabled />

        </form>

here my code insert.php

    session_start(); 
    $date = $_POST['data'] ;
    $client1 = $_POST['client1'] ;

    echo($client1);
    echo($date);

EDIT I tried this :

<input type="text" name="client1" class = "client" size="12" id ="client1"readonly />

here the error : Notice: Undefined index: client1 in C:\wamp\www\testlp\insert.php on line 12

Answer

cypherabe picture cypherabe · Apr 10, 2014

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.