How to send a message with disabled input

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

Here is my autocomplete.php code

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

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

        </form>

here is my insert.php code

    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's the error: Notice: Undefined index: client1 in C:\wamp\www\testlp\insert.php on line 12

+10
source share
4 answers

No value for customer 1. Add something like

value="TEST"

to your entrance.

echo $_POST['client1']; // TEST

Edit: delete session_start();Why are you using this?

-4
source

readonly disabled.

  • readonly:
  • disabled:
  • ( : input type = hidden: , )

, , , $_POST ( $_POST['client1'])

: - , name

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

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

, xml.

+54

,

<form action = 'insert.php' method="post"  >
  <input type="text" name="client1" class="client" size="12" id="client1" disabled />
  <input hidden name="client1" value="inserted_value_of_client1"/>
</form>

.
, php .

You can use <?php echo !empty($text)?$text:'';?>to fill in the fields valueas shown in some answers here

+2
source

If you want it to be disabled, so it does not change in the database, then you do not need to publish it. Use SELECT to populate <input>and add the attribute "disabled".

<?php
if ( !empty($_POST)) {
$other_inputs= $_POST['other'];

$valid = true;
if (empty($text)) {
    $valid = false;
}

if ($valid) {
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "UPDATE table set text = ? WHERE id = ?";
    $q = $pdo->prepare($sql);
    $q->execute(array($other_inputs,$id);
}
} else {
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "SELECT * FROM table where id = ?";
    $q = $pdo->prepare($sql);
    $q->execute(array($id));
    $data = $q->fetch(PDO::FETCH_ASSOC);
    $text = $data['client1'];
}
?>
<form action = 'insert.php' method="post"  >
    <input type="text" name="client1" class = "client" size="12" id ="client1" disabled vlaue="<?php echo !empty($text)?$text:'';?>" />
</form>
0
source

Source: https://habr.com/ru/post/1535941/


All Articles