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

问题描述 投票:0回答:1
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文件中传递的值?我对这两个主题都不了解,但是我正在经历这种需要。抱歉,抱歉我的英语。

javascript php arrays json sweetalert2
1个回答
0
投票

更新:

使用此代码:Sweet Alerts - Queue form为Swal.fire更改swal]

  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吗?例如?谢谢,非常感谢。

© www.soinside.com 2019 - 2024. All rights reserved.