php - 无法将我的表单数据传递给我的 php 函数
问题描述
在我的 Wordpress 网站上有一个带有邮政编码的表单,提交后它会将您带到该服务区域的静态页面。我无法将表单中的数据发送到我的 php 函数。我尝试过使用短代码属性并将表单操作设置为 zip-finder.php。任何帮助,将不胜感激..
表格:
/*<div class="zip"><form action="[zip_finder]" method='post'>Check pricing and availability in your city or town: <input name='zip' size="12" type="text" placeholder="Enter Zip Code" /> <button id="zip" type="submit">Get Started</button></form></div></p>
*/
I have added the line include('zip-finder.php'); to my theme functions.php file.
处理表单数据的 php 文件:
//<?php
function zipfinder_function() {
$zip=$_POST['zip'];
//commented out some things I tried to get it to work
/*$a = shortcode_atts( array(
'zip' => 'something',
'bar' => 'something else',
), $atts);*/
//switch ($atts['zip'])
switch ('zip')
{
case "02052":
header("Location: https://somewebsiteurl.com/");
break;
case "02056":
header("Location: https://somewebsiteurl.com/");
break;
case "02090":
header("Location: https://somewebsiteurl.com/");
break;
default;
//header("Location: https://websiteurl.com/");
break;
}
}
add_shortcode('zip_finder', 'zipfinder_function');
//?>
I've tried using short code attributes: [zip_finder zip="zip"]
解决方案
乍一看,您似乎正在切换静态值“zip”。尝试切换变量开关($zip)。
推荐阅读
- python - 如何用没有数据的列重构数据框
- flutter - 在 main 中发送一个参数并在小部件的构建中使用它(Flutter dart)
- unix - 如何在 Unix 的 head 和 tail 之间添加换行符?
- sqlite - 如何在一个 sql 表中加入所有内容并从另一个表中第一次出现,保留所有来自第一个表
- python - tensorflow 数据集在过滤后无法计算出 epoch 中的训练步数
- android - 当我收到意图时额外丢失
- c++ - 如何在我的 C++ 程序中链接和使用远程 cplex
- java - 单例 bean 是否与 Spring 中的所有用户共享数据?
- python-3.x - 如何将 def common_stats 集成到类 Data_Load 中?
- flutter - 如何在 Flutter 中将字符串转换为对象?