这是一个简单的“获取报价”页面,用户可以在其中输入零件编号,所需数量和任何可选注释。
事前研究我确保完全尝试在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:[email protected] 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: [email protected]
Phone: 800-555-1212
Parts: 1. PartNumber:p1 -- Qty: 1 -- Notes: No notes
2. PartNumber:p2 -- Qty: 3 -- N/A
感谢您的光临。任何帮助,将不胜感激。
注意:我正在使用KnockoutJS,所以我可以利用它们的2路数据绑定。不确定是否会影响该问题的答案。
真的没有什么。只要您有对视图模型的引用,就可能希望在代码中执行此操作,可以根据需要读取属性以生成字符串。
这可以是在可计算的可观察值中,也可以是仅用于生成字符串的常规单独函数中。
_emailContent() {
const {name,email,phone,parts} = this.customer();
return `Name: ${name()}
Email: ${email()}
Phone: ${phone()}
Parts:
${outputParts(parts)}
`;
function outputParts(parts) {
return ko.utils.arrayMap(parts(), ({partNumber,qty,notes}, i) =>
`${i+1}.\tPartNumber: ${partNumber()} -- Qty: ${qty()} -- Notes: ${notes()}`
).join('\n ');
}
}
我还制作了一个小提琴来演示它:https : //jsfiddle.net/3j1arh04/1/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句