php - 如何将以下提交按钮代码重定向到同一页面,如果可能的话不重新加载
问题描述
我创建了一个在 WordPress 网站弹出窗口中运行的代码,该代码的目的是验证 mysql db 表中可用的输入数据(如果可用)它显示相关代码,否则它执行其他代码。
我努力了
action="<?php echo $_SERVER['PHP_SELF']; ?>"
和
headlocation(.......)
但没有一个工作,它正在提交代码并重定向index.php
到显示结果。
<style><?php include 'search-zip.css'; ?>
</style>
<?php
include 'search-config.php';
$conn = OpenCon();
?>
<h3 class="formhead">Available in</h3>
<h2 class="formhead">Melbourne Inner Suburbs</h2>
<form class="form-wrapper" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="$POSTCODE" id="search" size="25" maxlength="35" value="<?php echo $_REQUEST['$POSTCODE'] ?>" />
<input type="submit"
name="submit" value="Search" id="submit"></form>
<p class="form-text">Please search your postal code for service availability</p>
<?
if (isset($_POST['submit'])) {
{
$zipcode=$_REQUEST['$POSTCODE'];
$sql = "SELECT * FROM service_location WHERE zipcode = $zipcode";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
?>
<style>.formhead{display:none;} .form-wrapper{display:none;} .form-text{display:none;}</style>
<div class="available">
<img class="zipimage" src="https://www.hastygrocer.com.au/wp-content/uploads/2019/07/hasty-grocer-available-popup-image.png" alt="Happy Minion" >
<h2 style="text-align: center;">Experience Melbourne's</h2>
<h2 style="text-align: center;"><i style="color: #3aafa9; font-family: Faster One script=all rev=2; font-size: 60px;">Fast</i> & <b style="color: green; font-family: Aladin; font-size: 60px;">Fresh </b></h2>
<h2 style="text-align: center;">Grocery Delivery</h2>
<span class="pum-close popmake-close "><button class="zipbutton" type="button">Shop</button></span></div>
<?
} else {
?>
<style>.formhead{display:none;} </style>
<div class="available">
<h3 style="text-align: center;">Get Notified When Available in <b style=" text-align: center;font-weight: 800; font-family: arial; color: #3aafa9;"><?php echo "$zipcode"?></b></h3>
<div class="zipform"><?php echo do_shortcode( '[contact-form-7 id="613" title="PopUp"]' ); ?></div>
</div>
<?
}
}}
?>
我创建了此代码以重定向到同一页面。
但这是重定向index.php
到显示结果。
请帮助我使用任何 php 修复此问题,或者ajax
可以修复此代码。
抱歉,我不是专家开发人员,我从 Internet 获取代码并创建了以下代码。
提前致谢
解决方案
请参阅这部分代码:action="<?php echo $_SERVER['PHP_SELF']; ?>"
提交将执行到从 $_SERVER 数组传递的链接,但 PHP 手册说:
$_SERVER 是一个包含标题、路径和脚本位置等信息的数组。此数组中的条目由 Web 服务器创建。无法保证每个 Web 服务器都会提供其中任何一个。
尝试制作<? echo $_SERVER['PHP_SELF']; ?>
并查看打印的内容。您可能会得到 index.php 的位置。
尝试将操作设置为包含表单的页面。
推荐阅读
- php - 如何在 PHP 中转换 MSB - LSB 格式处理
- c - 如果我包含来自不同目录的标头,则无法获取预处理的源文件或目标文件
- c# - 带有 Angular 6 捆绑文件的项目模板的 ASP.NET Core 404(错误的 dist 输出目录)
- sql - 电子邮件地址的 Sql Table 数据类型?
- reactjs - 使用 webpack 加载 react 图像
- python - python:在矩阵中选择y == 1且列为0的行
- function - 未来grails项目的方法实现
- nginx - 如何使用 ldap 对 nginx 进行身份验证?
- kubernetes - kubernetes 为许多副本提供公共 ip
- java - PUB/SUB 到 Bigquery 而不使用 DataFlow