dtdfj08626 2018-11-08 20:44 采纳率: 0%
浏览 45
已采纳

协助在html表单上传递json对象

Hello I have a multidimensional associative array I want to be able to send forward using POST on an html form. I thought this would be a simple matter but I think I am missing something.

here is where i encode the array into json:

$bottomInfoJson=json_encode($bottomInfo);

print_r($bottomInfoJson);

Just to show the json was properly encoded I printed it out and this is what i got:

 {
 "M1":{"amount":765,"instMrn":"100"},
"M2":{"amount":50,"instMrn":"100"},
"M3":{"amount":770,"instMrn":"100"},
"M4":{"amount":2159,"instMrn":"100"},
"M5":{"amount":145,"instMrn":"100"},
"M6":{"amount":500,"instMrn":"100"},
"M7":{"amount":7507,"instMrn":"100"},
"M8":{"amount":335,"instMrn":"100"},
"M9":{"amount":525,"instMrn":"100"},
"C10":{"amount":130,"instMrn":"100"}}

So I thought I could just pass this on a form simply since it is contained in the php variable...

Here is my form:

<form method='post' action="midMichSummary" enctype='application/json'>
<input type="hidden" name="sdate" value="<?php echo $sdate; ?>"/>

<input type="hidden" name="hbpb" value="<?php echo $hbpb; ?>"/>
<input type="hidden" name="bottomInfoJson" value="<?php echo $bottomInfoJson; ?>" />

<input type="submit" value="Summary->"/>

</form>

Basically all stuff is being passed fine except the json array - using print-r($_POST) at the destination shows me what has been passed...

So I am thinking there may be something additional i need to do to pass this properly - so I am hoping someone can help with this...

  • 写回答

1条回答 默认 最新

  • duandeng7132 2018-11-08 21:18
    关注

    I don't know what you get exactly in the $_POST["bottomInfoJson"] variable, but in case you got something like this "{", then the issue should be in the double quotation, you can simply try replacing the double quotation here:

    value="<?php echo $bottomInfoJson; ?>"
    

    with single quotation

    value='<?php echo $bottomInfoJson; ?>'
    

    It should work

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

报告相同问题?

悬赏问题

  • ¥15 Workbench中材料库无法更新,如何解决?
  • ¥20 如何推断此服务器配置
  • ¥15 关于github的项目怎么在pycharm上面运行
  • ¥15 内存地址视频流转RTMP
  • ¥100 有偿,谁有移远的EC200S固件和最新的Qflsh工具。
  • ¥15 找一个QT页面+目标识别(行人检测)的开源项目
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析