donoworuq450547191 2014-02-18 11:50
浏览 78
已采纳

PHP POST总是得到HTML表单的默认值

I'm working on some extensions to a 20 year old PHP code. Now I needed to add a new text input field and process the data as in all previously existing text input fields. Evrything works fine except for this new input.

I've got a HTML form:

<form action="form.php?<?php echo SID; ?>" method="post">
  <?php echo "<div id=\"inputheader-title\"><input type=\"text\" name=\"".$new.$i.'[position_new]'."\" size=\"3\" maxlength=\"2\" value=\"".$i."\">. Entry</div>"; ?>
  [...]
<input class="button" type="image" src="<?php echo $HTML_IMG; ?>/send.png">
</form>

[...] denotes further input fields, which are all working fine. All text input fields are using the same pattern.

The source code for the text field within my browser looks like this:

<input type="text" name="old1[position_new]" size="3" maxlength="2" value="1">

Which looks fine to me. But when I send the form data the value for old1[position_new] is always default in PHP's $_POST. All other data is correct (as inserted into the form fields). I checked that with var_dump($_POST)

When I examine the data sent by the browser I can see the modified value, but when it comes to PHP the data seems altered, despite it isn't processed any further.

In short: I entered: 3

Default value is: ["position_new"]=> string(1) "1"

The browser shows: ["position_new"]=> string(1) "3"

var_dump($_POST) shows: ["position_new"]=> string(1) "1"
  • 写回答

1条回答 默认 最新

  • dousi1961 2014-02-18 12:02
    关注

    PHP transforms fields with [] in name into an array. If you don't want this, remove [ and ] from field name.

    <?php
      var_dump($_REQUEST);
      echo '<pre>'.print_r($_REQUEST,true).'</pre>';
    ?>
    <form action="/test.php" method="post" name="myform">
      <input type="text" name="old1[position_new]" size="3" maxlength="2" value="1">
      <input type="text" name="old1[art]" size="15" maxlength="50" value="Lecture">
      <input type="submit" name="save" value="save">
    </form>
    

    In this example, with your fields names, array is correctly populated. Check for a duplicate field with same name with a default value in your html code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失