【发布时间】:2019-04-09 12:39:24
【问题描述】:
在我的 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"]
【问题讨论】:
-
action="[zip_finder]"这是您的实际代码吗? Action 应该是一个 URL -
是的,这就是代码。 action='[zip_finder]'
-
是的,这就是代码。 action='[zip_finder]' 它确实有效。在 php 文件中,如果我设置 $zip=02056;它将转到邮政编码和服务区域的正确页面。我无法从表单中获取数据来工作。
标签: php wordpress forms shortcode