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

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

將用戶重定向到頁面后如何在輸入和tinymce textarea中回顯會話變量

將用戶重定向到頁面后如何在輸入和tinymce textarea中回顯會話變量

PHP
慕尼黑8549860 2022-07-29 12:27:14
我正在嘗試處理表格。如果有錯誤,用戶將被重定向到表單,錯誤將在此處顯示,用戶嘗試提交的任何內容都會在表單的 tinymce 的 textarea 中回顯。這樣,用戶就不必再次重寫所有內容。一切都運行良好,除了用戶被重定向后會話變量不會在 tinymce 編輯器中回顯。會話變量已設置并具有正確的值。如果我在 tinymce 之外回顯會話變量,它會按預期顯示。它只是不會出現在文本區域中。我該如何解決?另外,我知道這很容易受到 xss 的影響。我想讓用戶格式化他們的帖子,所以稍后我將通過 HTML Purifier 運行它。添加新線程.php:<?php session_start(); if($_SERVER['REQUEST_METHOD']==='POST'){   if(isset($_POST['submit'])&&$_POST['submit']==='success'){    if (empty(trim($_POST['thread-title'])))    {        $_SESSION['forum_titErr'] = "<p class='error text-center'>Error message</p>";    }    else    {        $_SESSION['threadTitle'] = $_POST['thread-title'];     }    if (empty(trim($_POST['thread-content'])))    {        $_SESSION['forum_thrContErr'] = "<p class='error text-center'>Error message </p>";     }    else    {        $_SESSION['threadCont'] = $_POST['thread-content'];    }    if((isset($_SESSION['forum_titErr'])&&!empty($_SESSION['forum_titErr']))|| (isset($_SESSION['forum_thrContErr'])&&!empty($_SESSION['forum_thrContErr'])))    {        header("Location: newthread.php?submit=error");     }    else     {    //insert into database and redirect to readtopic.php if insert is successful; else redirect to form and show insert is not successful     }}else{    header("Location: newthread.php");}}else{      exit('invalid request');}?>表單html:<!DOCTYPE html><html><?php       session_start(); ?><head>    <!-- title, meta, stylesheet, etc. -->     <script type="text/javascript" src="jquery.js"></script>    <script src="https://cdn.tiny.cloud/1/no-api-key/tinymce/5/tinymce.min.js" referrerpolicy="origin"></script>    <script>tinymce.init({selector:"#threadCont", height: 300, resize: false    });</script></head>
查看完整描述

3 回答

?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

我認為你需要這樣做


 <form action='addnewthread.php' method='post'>

      <input type='text' name='thread-title' id='thread-title' placeholder='Type title here' class='user-input'

           <?php 

           if(isset($_SESSION['threadTitle']) && !empty($_SESSION['threadTitle']))

           {

                echo "value='{$_SESSION['threadTitle']}'"; 

           }

           ?>

      >

      <textarea id='threadCont' name='threadCont'>

      <?php 

            if(isset($_SESSION['threadCont']) && !empty($_SESSION['threadCont']))

            {

                 echo $_SESSION['threadCont'];

            }

      ?> 

      </textarea>

      <button id='submit' type='submit' name='submit'value='success'>Submit</button>

</form>


查看完整回答
反對 回復 2022-07-29
?
拉風的咖菲貓

TA貢獻1995條經驗 獲得超2個贊

只需回顯變量,只需注意"and'因為字符串連接。


對于輸入:


 <input type='text' name='thread-title' id='thread-title' placeholder='Type title here' class='user-input'

 <?php 

    if(isset($_SESSION['threadTitle'])&!empty($_SESSION['threadTitle'])

     {

     echo "value='".$_SESSION['threadTitle']."'"; 

  }

  ?>

  />

對于文本區域:


  <textarea id='threadCont' name='threadCont'>

  <?php 

  if(isset($_SESSION['threadCont'])&!empty($_SESSION['threadCont'])

  {

   echo $_SESSION['threadTitle'];

  }

  ?> 

  </textarea>


查看完整回答
反對 回復 2022-07-29
?
侃侃爾雅

TA貢獻1801條經驗 獲得超16個贊

我檢查了您的代碼,發現您忘記添加圓括號:


<form action='addnewthread.php' method='post'>

    <input type='text' name='thread-title' id='thread-title' placeholder='Type title here' class='user-input'

        <?php

        if(isset($_SESSION['threadTitle'])&&!empty($_SESSION['threadTitle']) <--here

        {

            echo "value='{$_SESSION['threadTitle']}'";

        }

        ?>

    >

    <textarea id='threadCont' name='threadCont'>

          <?php

          if(isset($_SESSION['threadCont'])&&!empty($_SESSION['threadCont']) <--and here

          {

              echo $_SESSION['threadCont'];

          }

          ?>

          </textarea>

    <button id='submit' type='submit' name='submit'value='success'>Submit</button>

</form>

您還需要替換&為&&.


查看完整回答
反對 回復 2022-07-29
  • 3 回答
  • 0 關注
  • 214 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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