简体   繁体   English

如何根据表单输入值(即:邮政编码)显示不同的页面? jQuery 或 .PHP

[英]How to display different pages based upon form input value (ie: zip code)? jQuery or .PHP

Is there a jQuery, javascript, or .php script that would allow me to display different pages based upon a list of zip codes?是否有 jQuery、javascript 或 .php 脚本可以让我根据邮政编码列表显示不同的页面? 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.例如,如果用户在“有效”邮编列表中输入邮政编码,则将显示 pageA.php,否则将显示 pageB.php。 These zip code values could be manually listed out, or be contained within a .csv file, whatever is easiest.这些邮政编码值可以手动列出,或包含在 .csv 文件中,无论哪种方式最简单。

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>

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:例如在 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();

制作一个 php 文件,它将从 html 文件(具有密码)中获取数据,说使用 post 或 get 然后从 Excel 表或数据库中检查密码并执行所需的操作。

@mike & @ametren @mike和@ametren

I used the code you posted and tested in my web app. 我使用了您在Web应用程序中发布和测试的代码。 I would like to have the php app forward users to different web pages based on a select group of zip they enter. 我想让php应用根据用户输入的一组选定的zip将用户转发到不同的网页。 If they submit a zip not listed, they are directed to a generic page. 如果他们提交未列出的zip,则会将他们定向到常规页面。 Here is the code I used but could only get it to check one group of zip codes and forward to one web page: 这是我使用的代码,但只能获取它来检查一组邮政编码并转发到一个网页:

$special_zip_codes1 = array(
    '30331',
    '30334',
    '30336' // and so forth
);

$special_zip_codes2 = array(
    '31093',
    '31095',
    '31098',
    '31047' // and so forth
);

$zip = $_POST['zip'];

if(in_array($zip, $special_zip_codes1)) {
    header('Location: http://www.site1....');

} else {
    header('Location: http://www.notavailablesite....');

}

if(in_array($zip, $special_zip_codes2)) {
    header('Location: http://www.site2....');

} else {
    header('Location: http://www.notavailablesite....');

}

exit();

Could someone help with resolving this? 有人可以解决这个问题吗?

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

相关问题 页面之间的 php 表单上的输入值 - input value on php form between pages 使用PHP在不同页面(表单)之间传递值 - Pass value between different pages (form) with PHP 使用开放式输入字段,并使用它根据输入(例如邮政编码或PHP的状态)通过电子邮件发送三个不同的电子邮件地址之一? - Use open ended input field & use it to email one of three different email addresses based on input such as, zip code or state with PHP? 根据其他输入值使用jQuery AJAX通过PHP设置表单输入的值 - Set Value of Form Input using jQuery AJAX via PHP based on other Input Value PHP - 根据以下内容填充表单字段<select><option>价值 - PHP - Populate form fields based upon <select> <option> value 如何将输入乘以php中所选选项的值并显示在jQuery图表中? - How to multiply an input by the value of a selected option in php and display in a jQuery chart? 无法将php的值显示为html输入表单 - Cannot display value of php to html input form 如何基于会话/表单数据在PHP中有效或无效将用户重定向到其他页面? - How can I redirect users to different pages based on session/form data is valid or not in PHP? 如何根据用户在php中的选择提交表单字段? - How to filed form fields based upon user selection in php? 基于表单字段的不同页面 - Different Pages Based On Form Fields
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM