如何根据表单输入值(即:邮政编码)显示不同的页面? jQuery或.PHP [英] How to display different pages based upon form input value (ie: zip code)? jQuery or .PHP

查看:111
本文介绍了如何根据表单输入值(即:邮政编码)显示不同的页面? jQuery或.PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在一个jQuery,javascript或.php脚本,该脚本可让我根据邮政编码列表显示不同的页面?例如,如果用户在有效"邮政编码列表中输入邮政编码,则将显示pageA.php,否则,将显示pageB.php.这些邮政编码值可以手动列出,也可以包含在.csv文件中,这是最简单的方法.

Is there a jQuery, javascript, or .php script that would allow me to display different pages based upon a list of zip codes? For example, if the user enters a zip code within a list of 'valid' zips then pageA.php would display, if not then pageB.php would be displayed. These zip code values could be manually listed out, or be contained within a .csv file, whatever is easiest.

输入后显示的页面将基于用户输入,例如:

The page displayed after input would be based upon user input like:

<input name="zipcode" id="zipcode" type="text" />

有效的邮政编码最好列出为:

the valid zip codes ideally would be listed as:

<script>
var zipcodelist = ['12345','12346','12347','12348'];


更新的解决方案 这是我正在使用的代码:


UPDATED SOLUTION this is the code i'm using:

<script type="text/javascript">
$(function(){
    var zipCodes = ['92056', '90210', '92121', '92101'];

    $('#zip_form').submit(function(){
        $('#id_div_one, #id_div_two').hide();
        var theZip = $('#id_zip_code').val();
        if(jQuery.inArray(theZip,zipCodes) > -1) {
            $('#id_div_one').fadeIn();
        } else {
            $('#id_div_two').fadeIn();
        }
        return false;
    });
});
</script>

推荐答案

您可能只需要获取邮政编码的发布值,然后在应用程序逻辑中仅重定向到所需的页面即可.例如在PHP中:

You would probably just take the posted value for the zip code and then in your application logic just redirect to the page you want. For example in PHP:

$special_zip_codes = array(
    '10000',
    '10002',
    '10003' // and so forth
);

$zip = $_POST['zip_code'];
// need to add whatever validation/sanitation of zip code value here

if(in_array($zip, $special_zip_codes)) {
    header('Location: http://www.domain.com/fileA.php');
} else {
    header('Location: http://www.domain.com/fileB.php');
}
exit();

这篇关于如何根据表单输入值(即:邮政编码)显示不同的页面? jQuery或.PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆