简体   繁体   English

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

[英]Assist with passing json object forward on html form

Hello I have a multidimensional associative array I want to be able to send forward using POST on an html form. 您好,我有一个多维关联数组,我希望能够在html表单上使用POST转发。 I thought this would be a simple matter but I think I am missing something. 我以为这很简单,但是我想念一些东西。

here is where i encode the array into json: 这是我将数组编码为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: 只是为了显示json正确编码,我将其打印了出来,这就是我得到的:

 {
 "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... 所以我想我可以将其传递给表单,因为它包含在php变量中...

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... 基本上所有东西都可以通过json数组之外的其他方面很好地传递-在目的地使用print-r($ _ POST)可以告诉我已经通过了什么...

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... 因此,我认为我可能需要做些其他事情才能正确通过此操作-所以我希望有人可以对此提供帮助...

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: 我不知道您在$ _POST [“ bottomInfoJson”]变量中得到了什么,但是如果您遇到类似“ {”的问题,则问题应该在双引号中,您可以尝试替换双引号这里:

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

with single quotation 单引号

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

It should work 它应该工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM