Sweetalert2 Swal.mixin - 是否可以将输入数据提取到 json / php?


Using this code:
Swal.mixin({
input: 'text',
confirmButtonText: 'Next →',
showCancelButton: true,
progressSteps: ['1', '2', '3']
}).queue([
{
title: 'Question 1',
text: 'Chaining swal2 modals is easy'
},
'Question 2',
'Question 3'
]).then((result) => {
if (result.value) {
const answers = JSON.stringify(result.value)
Swal.fire({
title: 'All done!',
html: `
Your answers:
<pre><code>${answers}</code></pre>
`,
confirmButtonText: 'Lovely!'
})
}
})

在这种情况下,我的答案是:

["1","1","2"]

它如何接收在 PHP 文件中传递的值? 我对这两个主题都不太了解,但我正在经历这种需求。 对不起,对不起我的英语。

更新:

使用此代码:甜蜜警报 - 队列表单 为 Swal.fire 做零钱

var strAns1;
var strAns2;
swal.mixin({
input: 'text',
confirmButtonText: 'Next &rarr;',
showCancelButton: true,
progressSteps: ['1', '2', '3']
}).queue([
{
title: 'Question 1',
text: 'Chaining swal2 modals is easy',
preConfirm: function(value)
{
strAns1= value;
}
},
{
title: 'Question 2',
text: 'Chaining swal2 modals is easy',
preConfirm: function(value)
{
strAns2= value;
}
}
]).then((result) => {
if (result.value) {
Swal.fire({
title: 'All done!',
html:
'Your answers: <pre>' +
JSON.stringify(result) +
'<pre>Answer1- ' + strAns1+
'<pre>Answer2- ' + strAns2+
'</pre>',
confirmButtonText: 'Lovely!'
})
}
})

改变

swal({
title: 'All done!',
html:
'Your answers: <pre>' +
JSON.stringify(result) +
'<pre>Answer1- ' + strAns1+
'<pre>Answer2- ' + strAns2+
'</pre>',
confirmButtonText: 'Lovely!'
})
}
})
To
Swal.fire({
title: 'All done!',
html:
'Your answers: <pre>' +
JSON.stringify(result) +
'<pre>Answer1- ' + strAns1+
'<pre>Answer2- ' + strAns2+
'</pre>',
confirmButtonText: 'Lovely!'
})
}
})

我得到的结果是:

{"value":["adf","fffff"]}
Answer1- adf
Answer2- fffff

现在我可以把它传递给 php 吗? 比如说? 谢谢,非常感谢。

最新更新