I am working on a form that will redirect users based on a form. The form asks for a zipcode. If the zipcode is correct (one of the zipcodes in the service area) then I want to redirect to an order page. If the zip code is incorrect, not in service area, then I want to redirect to a different URL.
Here is what I have so far... It works, kinda. The problem is no matter what you enter into the form the user is redirected to the order page.
Form code:
<form class="form-horizontal" role="form" method="post" action="<?php bloginfo('template_directory');?>/zip-checker.php">
<div class="form-group">
<label>Pleasee add your zip code to get started...</label>
<input type="text" class="form-control" placeholder="90001" required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-lg btn-block"><span class="glyphicon glyphicon-chevron-right"></span> Next</button>
</div>
</form>
Zip Checker PHP Code:
<?php
$loc1 = array(90001, 90002, 90003, 90004, 90005, 90006, 90007, 90008, 90010, 90011, 90012, 90013, 90014, 90015, 90016, 90017, 90018, 90019, 90020, 90021, 90023, 90024, 90025, 90026, 90027, 90028, 90029, 90031, 90032, 90033, 90034, 90035, 90036, 90037, 90038, 90039, 90041, 90042, 90043, 90044, 90045, 90046, 90047, 90048, 90049, 90056, 90057, 90058, 90059, 90061, 90062, 90063, 90064, 90065, 90066, 90067, 90068, 90069, 90071, 90077, 90079, 90089, 90090, 90094, 90095, 90210, 90212, 90230, 90232, 90247, 90248, 90272, 90275, 90290, 90291, 90292, 90293, 90402, 90405, 90501, 90502, 90710, 90717, 90731, 90732, 90744, 90745, 90810, 90813, 91030, 91040, 91042, 91105, 91214, 91303, 91304, 91306, 91307, 91311, 91316, 91324, 91325, 91326, 91330, 91331, 91335, 91340, 91342, 91343, 91344, 91345, 91352, 91356, 91364, 91367, 91371, 91401, 91402, 91403, 91405, 91406, 91411, 91423, 91436, 91504, 91505, 91601, 91602, 91604, 91605, 91606, 91607, 91608);
$search_zip = (int) substr($_GET['location'], 0, 5);
// - next check to see which location array has this zip code
// if none, then location = 0 - not in our service area
if (in_array($search_zip, $loc1))
{
$location = 1;
}
else
{
$location = 0;
}
if ($location)
{
header("Location: http://dr.gorillaadvertising.net/no-service-in-your-area/");
}
else
{
header("Location: http://dr.gorillaadvertising.net/order-dry-cleaning/");
}
?>