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

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

在 php 端更改 div 屬性

在 php 端更改 div 屬性

PHP
喵喵時光機 2022-11-12 10:00:02
我正在制作一個簡單的 Php 和 javascript 項目,其中我的 css 設計中有一些覆蓋設計?,F在我有一個按鈕,單擊它會顯示一個名為“myNav”的覆蓋 div,其中有一個名為“req_form”的 div 和表單,用戶可以在其中填寫輸入并提交它們,然后我的 php 代碼將這些數據存儲在我的數據庫中。在我的 Php 代碼中成功提交數據后,我只是不知道如何替換 div 并在其上顯示成功。我的覆蓋 div<?phpinclude 'includes/autoloader.inc.php';?><!DOCTYPE html><html><head><script type="text/javascript">  function openNav() {    document.getElementById("myNav").style.width="100%";  }  function closeNav(){    document.getElementById("myNav").style.width = "0";  }</script><link rel="stylesheet" type="text/css" href="css/cssticket.css"></head><body><button class="button_a" onclick="openNav()">Create Request</button> //OPENS THE OVERLAY DIV<div id="myNav" class="overlay"> // THIS IS THE OVERLAY DIV<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a><div class="overlay-content">    <div id="req_form" class="inputs"> // THIS IS THE DIV I WANT TO BE REPLACE BY A MESSAGE SUCCESS    <div id="error"></div>    <form id="form" action="includes/enduser.inc.php" method="POST">        <input type="text" name="userrequester" placeholder="name" >        <br>        <label for="reqtype">Request type:</label>        <select name="priority" required>            <option value="">Select</option>            <option value="High">General</option>            <option value="Low">Urgent</option>        </select>        <br>        <label for="itemtype">Item type:</label>        <input type="radio" name="typeitem" value="Borrowed" required><label>Borrowed</label>        <input type="radio" name="typeitem" value="Replace" required></input><label>Replace</label>        <br>        <label>Summary :</label>        <br>        <textarea name="summary" cols="30" rows="10" required ></textarea>        <br>        <button type="submit" name="sendrequest" class="button_a">Submit</button>        </div>    </form>    </div>    </div>       </body>    </html>我已經嘗試過的是在將數據存儲在此 php 文件中之后回顯一些應該將其更改為成功消息的 javascript。
查看完整描述

1 回答

?
搖曳的薔薇

TA貢獻1793條經驗 獲得超6個贊

一旦您成功查詢并將輸入成功添加到數據庫,您將需要創建一個 header() 重定向到您的原始頁面。


像這樣的東西:


if (isset($_POST['sendrequest'])) {


    $date = date ('F d, Y');

    $enduser =  $_POST['userrequester'];

    $priority = $_POST["priority"];

    $itemtype = $_POST["typeitem"];

    $summary = $_POST["summary"];

    $status = "new";



    // Pretty sure this can be wrapped in your if statement, may need to test that.

    // --> $request->createticket($enduser, $priority, $itemtype, $status, $summary, $date); 

    if($request->createticket($enduser, $priority, $itemtype, $status, $summary, $date)){

        $postMSG = "success"; // sending the success message over url as $_GET

        $host  = $_SERVER['HTTP_HOST']; // SERVER

        $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); // Directory

        $extra = 'ticketformpage.php'; // the page your form is on

        header("Location: http://$host$uri/$extra?$postMSG"); // header redirect with url post added

    }

現在在您希望顯示成功消息的頁面上,我們檢查 GET 全局是否設置為成功$_GET['success'],如果成功則我們設置變量并顯示它們并添加一些 css。


<?php 

$msg = NULL; // we set to NULL for when the message is not needed

if(isset($_GET['success'])){

  $msg = "Thank you for submitting through our ticket system.";

}else{

  $msg = NULL;

}

注意:我在<span>標簽中添加了成功并添加了padding和border radius,limegreen bg和darkgreen顏色以與成功相關聯。10px margin-top for form。


 <div id="req_form" class="inputs">

    <span class="success"><?=$msg?></span> <!--// add the success variable here-->

    <div id="error"></div>

    <form id="form" action="inputtest.php" method="POST">

CSS:


form {

  margin-top: 10px;

}

.success {

   background-color: limegreen;

   color: darkgreen;

   padding: 10px;

   border-radius: 5px;

}

http://img1.sycdn.imooc.com//636efe5600012d3e03650305.jpg

查看完整回答
反對 回復 2022-11-12
  • 1 回答
  • 0 關注
  • 135 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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