gpt4 book ai didi

css 中的 PHP 变量不更新/刷新

转载 作者:太空宇宙 更新时间:2023-11-04 01:51:25 26 4
gpt4 key购买 nike

我遇到过这个非常烦人和奇怪的问题。它突然启动并正常工作。

我在我的(文档内)CSS 代码中使用名为“visibility”的 PHP 变量。
“可见性”根据具体情况而变化,这当然发生在 PHP 代码中。
可见性声明为全局 PHP 变量,并在 css 代码中正确实现。
据我所知,突然之间没有进行任何更改,当使用的 PHP 变量更改时,我的 css 不再更改。
然而,当我回显或转储可见性变量时,它给出了正确的值,但 css 保持页面首次加载时的状态。

我已经添加了 PHP header 和 HTML 元标记来防止缓存,但没有任何进一步的成功。

我将在下面添加我的 PHP 文件的所有代码,以便清楚地了解情况。

感谢您的帮助!

<?php

header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

$workMail = '***';
$workNumber = '***';
$visibility = 'hidden';

$errorMessage = array();
$mailOK = false;
$mailDone = false;

$mail = isset($_POST['mail']) ? $_POST['mail'] : null;
$tel = isset($_POST['tel']) ? $_POST['tel'] : null;
$firstName = isset($_POST['firstName']) ? $_POST['firstName'] : null;
$lastName = isset($_POST['lastName']) ? $_POST['lastName'] : null;
$subject = isset($_POST['subject']) ? $_POST['subject'] : null;
$message = isset($_POST['text']) ? $_POST['text'] : null;

if (isset($_POST['moduleAction']) && ($_POST['moduleAction'] == 'send')) {
if ($mail == null || strpos($mail, '@') == false) {
$errorMessage[] = 'Gelieve een correct emailadres op te geven';
}
if ($firstName == null) {
$errorMessage[] = 'Gelieve jouw voornaam te vermelden in het formulier';
}
if ($lastName == null) {
$errorMessage[] = 'Gelieve jouw achternaam te vermelden in het formulier';
}
if ($subject == null) {
$errorMessage[] = 'Gelieve een onderwerp te selecteren in het formulier';
}
if ($message == null) {
$errorMessage[] = 'Gelieve een mededeling te typen in het formulier';
}

if (sizeof($errorMessage) == null) {
$headers = 'From: ' . $mail . "\r\n" . 'Reply-To: '. $mail . "\r\n" . 'X-Mailer: PHP/' . phpversion();
if ($tel != null) {
$message .= "\r\n\r\n" . 'Telefoonnummer: ' . $tel;
}
var_dump($workMail, $subject, $message, $headers);
if (mail($workMail, $subject, $message, $headers)) {
$mailOK = true;
}
else {
$mailOK = false;
}
$mailDone = true;
}
}

$confirmationMessage;
if ($mailOK === true) {
$confirmationMessage = 'Danku voor uw mededeling! <br> Ik heb deze goed ontvangen, <br> en zal deze zo spoedig mogelijk beantwoorden';
}
else {
$confirmationMessage = 'Er is een fout opgetreden bij het verzenden van jouw mededeling, onze welgemeende excuses hiervoor! <br> u kan de mededeling opnieuw proberen verzenden of telefonisch contact opnemen met mij op het nummer ' . $workNumber;
}
if ($mailDone === true) {
$visibility = 'visible';
var_dump($visibility);
}

?>

<!DOCTYPE html>
<html lang="nl">
<head>
<title>MaximumRepair - Maak een afspraak</title>
<meta charset="uTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<link rel="stylesheet" type="text/css" href="css/start.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" type="text/css" href="css/afspraak.css">
</head>
<body>
<div id="wrapper">
<header>
<h1><a href="index.html" class="ir">MaximumRepair_Logo</a></h1>
<nav class="clearfix">
<h2 class="structural">Main navigation</h2>
<div class="left">
<ul>
<li><a href="index.html">Home</a></li>
<li class="active"><a href="afspraak.php">Maak een afspraak</a></li>
</ul>
</div>
<div class="right">
<ul>
<li><a href="diensten.html">Diensten</a></li>
<li><a href="tarieven.html">Standaard tarieven</a></li>
</ul>
</div>
</nav>
</header>

<div id="content">
<h2>Maak een afspraak</h2>
<section id="contactgegevens">
<h3 class="structural">Contactgegevens</h3>
<div>
<h4>Neem telefonisch contact op</h4>
<p>
SMS of bel naar het nummer: <br>
<span class="ir tel">tel_icon</span> <?php echo htmlentities($workNumber) ?>
</p>
</div>
<div>
<h4>Stuur een e-mail</h4>
<p><span class="ir mail">mail_icon</span> <a href="mailto:<?php echo htmlentities($workMail) ?>?" target="_blank"><?php echo htmlentities($workMail) ?></a></p>
<p>Of vul onderstaand formulier in</p>
</div>
<div>
<h4>Kom langs</h4>
<p>Mijn adres:</p>
<p>Kalkenstraat 14, 9255 Buggenhout</p>
</div>
</section>

<section>
<h3 class="structural">Contactformulier</h3>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<ul>
<li>
<label>Naam <span class="required">*</span></label>
<input type="text" name="firstName" class="field-divided" placeholder="Voornaam" value="<?php echo htmlentities($firstName) ?>" />&nbsp;<input type="text" name="lastName" class="field-divided" placeholder="Achternaam" value="<?php echo htmlentities($lastName) ?>" />
</li>
<li>
<label>Emailadres <span class="required">*</span></label>
<input type="email" name="mail" class="field-long" value="<?php echo htmlentities($mail) ?>" />
</li>
<li>
<label>Telefoonnummer</label>
<input type="tel" name="tel" class="field-long" value="<?php echo htmlentities($tel) ?>" />
</li>
<li>
<label>Onderwerp</label>
<select name="subject" class="field-select">
<option value="Herstelling" <?php if ($subject == 'Herstelling') echo 'selected' ?>>Herstelling</option>
<option value="Aankoop" <?php if ($subject == 'Aankoop') echo 'selected' ?>>Aankoop</option>
<option value="Opmerking website" <?php if ($subject == 'Opmerking website') echo 'selected' ?>>Opmerking website</option>
<option value="Andere" <?php if ($subject == 'Andere') echo 'selected' ?>>Andere</option>
</select>
</li>
<li>
<label>Jouw mededeling <span class="required">*</span></label>
<textarea rows="10" name="text" class="field-textarea"><?php echo htmlentities($message) ?></textarea>
</li>
<li>
<input type="submit" name="submit" value="Submit" />
<input type="hidden" name="moduleAction" id="moduleAction" value="send" />
</li>
</ul>
</form>
</section>
</div>

<footer>
<h2 class="structural">Footer</h2>
<ul>
<li>
<ul>
<li>Maximum Repair</li>
<li><img src="images/logo.png" alt="Maximum Repair logo"></li>
</ul>
<li>
<ul>
<li>Adres</li>
<li>Kalkenstraat 14</li>
<li>9255 Buggenhout</li>
</ul>
</li>
<li>
<ul>
<li>Contact</li>
<li>werknummer</li>
<li>werkemail</li>
</ul>
</li>
</ul>
</footer>

<div class="error">
<div id="errorMessage">
<span onclick="closeAndRefresh();">&#10006;</span>
<p id="message">
<?php echo $confirmationMessage ?>
</p>
</div>
</div>
</div>
<script>
function closeAndRefresh() {
<?php $visibility = 'hidden' ?>
window.location.reload(true);
alert('refreshed');
var_dump('clicked');
}
</script>
</body>

<style type="text/css">
/* Error */

.error {
visibility: <?php echo htmlentities($visibility) ?>;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(80, 80, 80, 0.8);
z-index: 2;
}

#errorMessage {
background-color: #fff;
width: 40%;
padding: 5rem;
margin: 20% auto;
border: 3px solid #94618E;
z-index: 3;
text-align: center;
position: relative;
}

#errorMessage span {
display: block;
width: 2rem;
height: 2rem;
line-height: 2rem;
font-size: 1.4rem;
background-color: #94618E;
color: #F4DECB;
position: absolute;
top: 0;
right: 0;
cursor: pointer;
}
</style>
</html>

最佳答案

问题似乎是 CSS 缓存,就像 Jesse de gans 之前指出的那样。

我为这种情况找到的唯一解决方案是,
1:使用 Twig 并禁用 CSS 缓存(但在这种情况下使用 Twig 似乎有点矫枉过正)。
2: 将满足所需条件时必须显示的 HTML 放在 PHP if 语句中,这样就不需要 CSS 更新。

关于css 中的 PHP 变量不更新/刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43426266/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com