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;
}
- 1 回答
- 0 關注
- 135 瀏覽
添加回答
舉報