![](/img/trans.png)
[英]how to run php code on submit button without refreshing/ reloading the page
[英]How to redirect following submit button code to same page and if possible without reloading
我创建了一个在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
修复此问题。
抱歉,我不是专家开发人员,我从互联网上获取了代码并创建了以下代码。
提前致谢
参见这段代码: action="<?php echo $_SERVER['PHP_SELF']; ?>"
提交将执行到$ _SERVER数组传递的链接,但是PHP手册说:
$ _SERVER是一个包含标题,路径和脚本位置等信息的数组。 该数组中的条目由Web服务器创建。 不能保证每个Web服务器都会提供其中的任何一个。
尝试制作<? echo $_SERVER['PHP_SELF']; ?>
<? echo $_SERVER['PHP_SELF']; ?>
<? echo $_SERVER['PHP_SELF']; ?>
并查看打印的内容。 您可能会得到index.php位置。
尝试将操作设置为包含表单的页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.