作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的代码:
<script src="https://sdk.paylike.io/3.js"></script>
<script>
var paylike = Paylike('***');
document.querySelector('button').addEventListener('click', pay);
function pay(){
paylike.popup({
// locale: 'da', // pin popup to a locale
title: 'Product',
description: '<?php echo $amount; ?>',
currency: 'GBP',
amount: <?php echo $price; ?>,
// saved on transaction for retrieval from dashboard or API
custom: {
// arrays are fine
products: [
// nested objects will do
],
},
// data from fields will be merged with custom
fields: [
// elaborate custom field
{
name: 'name',
type: 'name',
placeholder: 'John Doe',
required: true,
},
{
name: 'email',
type: 'email',
placeholder: 'john@example.com',
required: true,
},
{
name: 'address',
type: 'address',
placeholder: 'Address',
required: true,
},
{
name: 'postcode',
type: 'postcode',
placeholder: 'Postcode',
required: true,
},
],
}, function( err, res ){
if (err)
return console.log(err);
console.log(res);
location.href = 'success.php?e=' + email;
});
}
</script>
我希望能够获取在此弹出表单中提交的电子邮件,以便我可以将其附加到成功 URL,从而发送电子邮件收据。然而,我的尝试似乎并没有奏效。
这是控制台的输出:
Object
custom: Object
address: "116"
email: "test@gmail.com"
name: "John Doe"
postcode: "E9 7SR"
transaction: Object
id: "581b23717cb2057463e8d76a"
如何返回电子邮件对象?
预先感谢您的帮助。
最佳答案
尝试:
res.custom.email
翻译为:
location.href = 'success.php?e=' + res.custom.email;
我认为你应该使用 encodeURIComponent 来转义该值。电子邮件对于 URL 来说可能不是问题,但我认为这是一个好习惯:
location.href = 'success.php?e=' + encodeURIComponent(res.custom.email);
下次遇到类似问题时,请尝试将 debugger;
(断点)放入代码中(在此示例中,紧接在 }, function( err, res ){
),在 Google Chrome 中启动开发人员工具,重新加载,然后脚本将运行但在断点处停止,允许您在该确切点检查变量及其值。
关于javascript - 如何返回自定义表单字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40392500/
我尝试通过正则表达式将文本中的单引号更改为双引号。 (单字)示例:我走了。 You gona fly to planet 'Ziqtos' => 我需要在 I'm 中保留单引号,并在 You gona
我正在构建一个 API,其中大部分将包含 JSON 和 HTML 内容。但是一些非常具体的端点只呈现 true 或 false,并且还在 POST 中接受 true 或 false。这是请求或响应的整
我是一名优秀的程序员,十分优秀!