gpt4 book ai didi

javascript - 如何返回自定义表单字段的值

转载 作者:行者123 更新时间:2023-11-28 05:22:57 24 4
gpt4 key购买 nike

这是我的代码:

<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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com