duancanjiu3754 2011-08-25 14:25
浏览 104
已采纳

在$ _POST变量中传递额外数据

I need to pass an id along with a form field e.g

<input name="__field_name" value="1234" />

this only passes the name and value as a key => value pair. i need to keep the name (dynamically entered by the user) and value intact for later use, but i also need to pass an ID along with this var.

how can i do this cleanly? i was thinking putting it in the name and doing a regex to seperate it e.g.

__field_name__ID  

although this seems messy...

points to consider:

  • there are allot of post variables that are generated by the CMS (wordpress) that i wont use
  • name must be retained in original format along with value
  • 写回答

3条回答 默认 最新

  • doujiufutaog59220 2011-08-25 14:28
    关注

    Why not submit the data as an array?

    Instead of calling your field __field_name__id or some mess, use the facilities PHP provides: Call your input field field_name[id] and when the form is posted back to the server, PHP's $_POST array will have a sub-array called field_name which contains the key=>value mappings you'd mentioned.

    If you have two such fields you want to tie together, use the following:

    <input type="text" name="myFields[id]" />
    <input type="text" name="myFields[name]" />
    

    And on postback, PHP will provide you with a $_POST['myFields']['id'] and $_POST['myFields']['name'].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图