亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 = "[email protected]";                    $Subject = "New Feedback";                    $mailTo = "[email protected]";                    $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 關注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號