简体   繁体   English

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

[英]Sweetalert2 Swal.mixin - is it possible to extract input data to 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!'
    })
  }
})

In this case, my answers:在这种情况下,我的回答是:

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

how could it receive the values ​​passed in a php file?它怎么能接收到一个php文件中传递过来的值呢? I do not know well about both subjects, but I am experiencing this need.我对这两个主题都不太了解,但我正在经历这种需求。 Sorry, and sorry for my english.对不起,对不起我的英语。

Update:更新:

Using this code: Sweet Alerts - Queue form Make change swal for Swal.fire使用此代码: Sweet Alerts - Queue form Make change swal for 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!'
        })
      }
    })

Change改变

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!'
    })
  }
})

Im get in result this:我得到的结果是:

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

Now can I pass this on to a php?现在我可以将其传递给 php 吗? Like for example?比如说? Thank you thank you very much.谢谢 非常感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM