Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
962 views
in Technique[技术] by (71.8m points)

php - How do I post disabled input

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:wampwwwestlpinsert.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:wampwwwestlpinsert.php on line 12

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...