繁体   English   中英

无法将我的表单数据传递给我的php函数

[英]Can not get my form data passed to my php function

在我的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)。

https://www.php.net/manual/en/control-structures.switch.php

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM