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

在 php 端更改 div 属性

在 php 端更改 div 属性

PHP
喵喵时光机 2022-11-12 10:00:02
我正在制作一个简单的 Php 和 javascript 项目,其中我的 css 设计中有一些覆盖设计。现在我有一个按钮,单击它会显示一个名为“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;

}

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

查看完整回答
反对 回复 2022-11-12
  • 1 回答
  • 0 关注
  • 120 浏览

添加回答

举报

0/150
提交
取消
微信客服

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

帮助反馈 APP下载

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

公众号

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