[英]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.