The*_*oge 11 php post input disabled-input
你好,我有一些投入,但他们中的一个被禁用(是,我需要为我的时间表),但我怎么把它给autocomplete.php我insert.php已经这个错误未定义指数:用C客户端1:\ WAMP \第30行的www\testlp\insert.php
这是我的代码autocomplete.php
<form action = 'insert.php' method="post" >
<input type="text" name="client1" class = "client" size="12" id ="client1" disabled />
</form>
Run Code Online (Sandbox Code Playgroud)
这里是我的代码insert.php
session_start();
$date = $_POST['data'] ;
$client1 = $_POST['client1'] ;
echo($client1);
echo($date);
Run Code Online (Sandbox Code Playgroud)
编辑 我试过这个:
<input type="text" name="client1" class = "client" size="12" id ="client1"readonly />
Run Code Online (Sandbox Code Playgroud)
这里的错误: Notice: Undefined index: client1 in C:\wamp\www\testlp\insert.php on line 12
cyp*_*abe 62
使用属性readonly而不是disabled.
您收到错误,因为提交表单时未发送禁用的元素,因此不存在$_POST($_POST['client1']在您的情况下根本没有)
编辑编辑:示例不完整 - 正如接受的答案所述,该name属性也必须存在
<input type="text" name="client1" class = "client" size="12" id ="client1" value="something" readonly />
Run Code Online (Sandbox Code Playgroud)
要么
<input type="text" name="client1" class = "client" size="12" id ="client1" value="something" readonly="readonly" />
Run Code Online (Sandbox Code Playgroud)
如果你想拥有更像xml的语法.
这是如何解决这个问题的想法
<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>
Run Code Online (Sandbox Code Playgroud)
您甚至可以从第一个输入中删除名称。
这样,您禁用的输入仍将显示,但 php 会在您的隐藏输入字段中发布该值。
您可以使用
此处的某些答案<?php echo !empty($text)?$text:'';?>来填充value字段
TLDR;
<form action="index.php" method="post">
<input type="text" disabled value="my_value"/>
<input hidden name="client" value="my_value"/>
</form>
Run Code Online (Sandbox Code Playgroud)