【发布时间】:2020-02-14 21:41:31
【问题描述】:
应用概览
这是一个简单的“get-a-quote”页面,用户在其中输入零件编号、所需的数量,以及任何可选的注释。
先前的研究 对于与我类似的问题,我确保彻底尝试在 StackOverflow 上找到的解决方案。我尝试了很多,包括以下内容(我发布这个是为了向你保证,在发布这个问题之前我已经尽力了):
(还有更多,我试过了)- 话虽这么说......
问题
我无法将表单值发布到我的 PHP 流程页面。我正在使用 JQuery Ajax 发布。具体来说,我不知道如何访问“部分”,它可能包含也可能不包含多个。
期望的结果
检索所有表单数据,并使用 PHP 发送电子邮件。
我不需要电子邮件部分的帮助,只需要表单值。
PHP 处理程序
// Receive JSON
$json = file_get_contents('php://input');
// Converts it into a PHP object
$data = json_decode($json, true);
foreach($data as $key => $value)
{
echo $key.' value of the key is:'.$value;
}
已发布的值
来自 PHP 页面的响应
name value of the key is:Johnemail value of the key is:john@gmail.comphone value of the key is:808-333-3333<br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Array to string conversion in C:\wamp64\www\123NEW\process.php on line <i>11</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0006</td><td bgcolor='#eeeeec' align='right'>406152</td><td bgcolor='#eeeeec'>{main}( )</td><td title='C:\wamp64\www\123NEW\process.php' bgcolor='#eeeeec'>...\process.php<b>:</b>0</td></tr>
</table></font>
parts value of the key is:Array
应用预览
理想情况下,我希望得到一个可以通过电子邮件发送的格式化字符串:
Name: John
Email: john@gmail.com
Phone: 800-555-1212
Parts: 1. PartNumber:p1 -- Qty: 1 -- Notes: No notes
2. PartNumber:p2 -- Qty: 3 -- N/A
感谢收看。任何帮助将不胜感激。
注意: 我正在使用KnockoutJS,所以我可以利用他们的 2 路数据绑定。不确定这是否会影响对这个问题的回答。
【问题讨论】:
标签: php json knockout.js