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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器