无法获得$ _post的形式价值
问题描述:
我想通过$ _post在我的插入页面中获取我的表单的输入值,但我的问题是,我得到错误消息:undefined index:track_code,我无法获得它的价值。名字一样是什么问题? 这是我的问题,为什么stackoverflow想要更多的细节。这是所有细节
<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd ; ?>" style="width: auto;height: auto" disabled />
</form>
<form action="insert.php" method="post" class="form-horizontal form-checkout">
<div class="control-group">
<label class="control-label" for="firstName">نام<span class="red-clr bold">*</span></label>
<div class="controls">
<input name="first_name" type="text" id="firstName" class="span4" >
</div>
</div>
<div class="control-group">
<label class="control-label" for="lastName">نام خانوادگی<span class="red-clr bold">*</span></label>
<div class="controls">
<input name="last_name" type="text" id="lastName" class="span4">
</div>
</div>
<input name="submit" type="submit" class="btn btn-success" value="خرید" style="width: 66px"/>
</form>
<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd ; ?>" style="width: auto;height: auto" disabled />
</form>
<?php
$track_code = $_POST['track_code'];
?>
答
尝试将PHP代码放在窗体上。如下所示。
<?php
if (isset($_POST['submit'])) {
$track_code = $_POST['track_code'];
}
?>
<form action="your_page.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo $track_code_rnd; ?>" style="width: auto;height: auto" readonly />
<input name="submit" type="submit" />
</form>
它会执行整个文件为PHP。第一次打开时,$_POST['submit']
将不会被设置,因为表单尚未发送。一旦你点击提交按钮,它将打印信息。
禁用的控件从不在服务器上发布。所以只能将其设为只读或隐藏。
+0
@Sinak试试这种方法,输入值属性中的逗号。或者你可以像这样做' –
答
设置您的形式
<form action="insert.php" method="post">
<input name="track_code" type="text" class="tiny-size" value="<?php echo ($track_code_rnd)?$track_code_rnd:'';?>" style="width: auto;height: auto" disabled />
</form>
答
这个代码从输入码删除禁用标记。禁用控件不会在服务器上发布。因为你可以使它只读或使其隐藏
可能重复[PHP:“注意:未定义的变量”,“注意:未定义的索引”和“注意:未定义的偏移量”](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) –
你在哪里提交按钮? – Exprator
@Exprator我有两种形式,该表单已提交。我很困惑 。最新的解决方案? – sinak