为了账号安全,请及时绑定邮箱和手机立即绑定

Sweetalert2 textarea 输入显示在电子邮件上

Sweetalert2 textarea 输入显示在电子邮件上

PHP
翻翻过去那场雪 2023-03-04 10:08:28
我如何设法接收文本区域内用户的输入?以下是我更详细的意思:https://i.stack.imgur.com/trG1E.gif 我的 JS 看起来像这样:$('#sad').on('click', function() {    const sad    = $('#sad').val();     const { value: text } = Swal.fire({        title:'<strong>Lass uns mehr erfahren</strong>',        input: 'textarea'    }).then(function() {    $.ajax({        type: "POST",        url: "feedback.php",//===PHP file name and directory====        data:{sad: sad},    success:function(data){        console.log(data);        //Success Message == 'Title', 'Message body', Last one leave as it is        Swal.fire({        icon: 'success',        title: "Danke!",        showConfirmButton: false,        timer: 3000    });    },    error:function(data){        //Error Message == 'Title', 'Message body', Last one leave as it is        Swal.fire({            icon: 'error',            title: 'Oops...',            text: 'Something went wrong!'})}});if (text) {    $.ajax({         type: "POST",          url: "feedback.php",          data: {'text': text}        })}})})和我的 PHP:$sad = $_POST['sad'];$text = $_POST['text'];    elseif(isset( $_POST['sad'] )) {                     $EmailFrom = "xxxxxxxx@gmail.com";                    $Subject = "New Feedback";                    $mailTo = "info@xxxxxxxx.me";                    $txt = "Oh no, you got a new 'Sad' review".$text;                    $headers = 'From: ' .$EmailFrom. "\r\n";                    mail($mailTo, $Subject, $txt, $headers);                    header("Location: https://xxxxxxxx.me/?mailsend");                    }我收到了 $txt 部分,但没有收到每封电子邮件的用户输入:“哦,不,你收到了一条新的‘悲伤’评论”
查看完整描述

1 回答

?
墨色风雨

TA贡献1853条经验 获得超6个赞

在下面的代码中,我已经在内部传递了 textarea 的值function(result),然后我习惯了result.value访问 textarea 的值并将其传递给 ajax 调用。

演示代码

$('#sad').on('click', function() {

  const sad = $('#sad').val();

  const {

    value: text

  } = Swal.fire({

    title: '<strong>Lass uns mehr erfahren</strong>',

    input: 'textarea'

  }).then(function(result) {

  //chcking if user have type something in textbox

    if (result.value) {

    //printing in console

      console.log(result.value)

      $.ajax({

        type: "POST",

        url: "feedback.php", //===PHP file name and directory====

        data: {

          sad: sad,

          values: result.value //<-sending textarea value

        },

        success: function(data) {

          console.log(data);

          //Success Message == 'Title', 'Message body', Last one leave as it is

          Swal.fire({

            icon: 'success',

            title: "Danke!",

            showConfirmButton: false,

            timer: 3000



          });

        },

        error: function(data) {

          //Error Message == 'Title', 'Message body', Last one leave as it is

          Swal.fire({

            icon: 'error',

            title: 'Oops...',

            text: 'Something went wrong!'

          })

        }

      });


    }

    if (text) {

      $.ajax({

        type: "POST",

        url: "feedback.php",

        data: {

          'text': text

        }

      })

    }

  })

})

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>


<button id="sad">Click</button>

然后,您需要使用 php 获取在 ajax 中传递的值$_POST['values']



查看完整回答
反对 回复 2023-03-04
  • 1 回答
  • 0 关注
  • 177 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号