使用PHP对简单表单进行多重定向

Please can anyone help me on this form, I need to have this done pretty much right now for my client and I am lost! Not the best at PHP. What needs to happen is whenever a user fills out the form it needs to redirect the URL based on the inputs added for the form. For example if they choose any of the drop-downs listed it will take them to that specific page. I actually got all of that working through javascript as shown. The next part where I need help is when they enter a correct zip code being that of San Diego, it will take them to the page that they chose in the drop-down. If they don't input a correct zip code of San Diego, it will take them to a a different 'nation wide page'. Completely overriding the drop-down selections. I really need help with this, can anyone please help me out? Thanks for any input that can be added because I am super lost on what to do right now...

<script type="text/javascript">

    function setAction(nPage){

        document.forms[0].action = nPage;
    }
</script>

<?php
    $zip = $_GET['zip'];

    $sandiego =  array('91911', '91914', '91915', '91932', '91942', '91945', '91950', '92014', '92025', '92027', '92029', '92037', '92064', '92065', '92067', '92071', '92075', '92101', '92102', '92103', '92104', '92105', '92106', '92107', '92108', '92109', '92110', '92111', '92113', '92114', '92115', '92116', '92117', '92118', '92119', '92120', '92121', '92122', '92123', '92124', '92126', '92127', '92128', '92129', '92130', '92131', '92132', '92134', '92135', '92139', '92140', '92145', '92147', '92154', '92173');

    if (in_array($zip, $sandiego)){
        header("Location: http://www.pureflo.com/");
    } else {
            header("Location: http://www.pureflo.com/");
    }

?>

<form method='post' enctype='multipart/form-data'  id='gform_1'  action='front-page.php'>
<div class="serviceinput"
<label for="services">Services: </label>
<select id="selection" onchange="setAction(this.value)">

<option value=''>Select a Service</option>
<option value='http://50.22.79.62/~pftech/water-delivery-service/'>Water Delivery</option>
<option value='http://50.22.79.62/~pftech/coffee-delivery/'>Coffee Services</option>
<option value='http://50.22.79.62/~pftech/water-filtration-systems/'>Water Filtration</option>
</select>

</div>
&nbsp;
<div class="zipcode">
<label for="zip">Zip Code: </label>
<input name="zip" type="text" maxlength="5" id="zip" /></div>
<div class="frontradio"><input name="home" type="radio" id="homeradio" />
   <div class="homelabel"> <label for="homeradio">Home</label></div>
    <input name="home" type="radio" id="officeradio" />
    <label for="officeradio">Office</label></div>
<div class="homebutton">
<input type='submit' id="submithome" name="did_submit" value="Get Started!">
</div>
</form>

Are you sure this functionality is what you need? You want to change the action of the form instead of handling the redirecting in one spot?

Let's start here: Your form is using post, but you look for $_GET['zip']. You need to change that to listen for one or the other. Since this looks like a filtering form, I suggest using get:

<form method='get' id='gform_1' action='front-page.php'>

You don't need enctype there, and your method should be get. Now, your submission code should have isset around it:

if(isset($_GET['zip'])){
    $sandiego =  array('91911', '91914', '91915', '91932', '91942', '91945', '91950', '92014', '92025', '92027', '92029', '92037', '92064', '92065', '92067', '92071', '92075', '92101', '92102', '92103', '92104', '92105', '92106', '92107', '92108', '92109', '92110', '92111', '92113', '92114', '92115', '92116', '92117', '92118', '92119', '92120', '92121', '92122', '92123', '92124', '92126', '92127', '92128', '92129', '92130', '92131', '92132', '92134', '92135', '92139', '92140', '92145', '92147', '92154', '92173');

    if (in_array($_GET['zip'], $sandiego)){
        header("Location: http://www.pureflo.com/"); // <- you sure about this?
    } else {
        header("Location: http://www.pureflo.com/");
    }
}

Your zip checker targets the same location for both. Perhaps you should utilize the select you made that currently has no name, so it won't populate in the get array:

    if (in_array($_GET['zip'], $sandiego)){
        header("Location: ".urldecode($_GET['selection'])."?zip=".$_GET['zip']."&type=".$_GET['type']);
    } else {
        header("Location: http://www.pureflo.com/");
    }
    exit;

And make sure to give your selection input html a name:

<select name="selection">

You do not need that js unless you really feel like writing submission handling code in several different places or including it. PS - you don't want to do that. If you do, you're confused.

Your radio buttons need values and should probably have a less specific name:

<input name="type" type="radio" id="homeradio" value="home" />
<input name="type" type="radio" id="officeradio" value="office" />

You may want to update your question with the actual intention of this form. I would assume it is requesting service information. Like - you say you want water for home and it should take you to something like:

http://50.22.79.62/~pftech/water-delivery-service/?zip=xxxxx&type=home

This is pretty simple.

Your whole code would be something like this:

<?php
    if(isset($_GET['zip'])){
        $sandiego =  array('91911', '91914', '91915', '91932', '91942', '91945', '91950', '92014', '92025', '92027', '92029', '92037', '92064', '92065', '92067', '92071', '92075', '92101', '92102', '92103', '92104', '92105', '92106', '92107', '92108', '92109', '92110', '92111', '92113', '92114', '92115', '92116', '92117', '92118', '92119', '92120', '92121', '92122', '92123', '92124', '92126', '92127', '92128', '92129', '92130', '92131', '92132', '92134', '92135', '92139', '92140', '92145', '92147', '92154', '92173');

        if (in_array($_GET['zip'], $sandiego)){
            header("Location: ".urldecode($_GET['selection'])."?zip=".$_GET['zip']."&type=".$_GET['type']);
        } else {
            header("Location: http://www.pureflo.com/");
        }
        exit;
    }
?>
<form method='get' id='gform_1' action='front-page.php'>
  <div class="serviceinput">
    <label for="services">Services: </label>
    <select id="selection" name="selection">
      <option value=''>Select a Service</option>
      <option value='http://50.22.79.62/~pftech/water-delivery-service/'>Water Delivery</option>
      <option value='http://50.22.79.62/~pftech/coffee-delivery/'>Coffee Services</option>
      <option value='http://50.22.79.62/~pftech/water-filtration-systems/'>Water Filtration</option>
    </select>
  </div>
  &nbsp;
  <div class="zipcode">
    <label for="zip">Zip Code: </label>
    <input name="zip" type="text" maxlength="5" id="zip" />
  </div>
  <div class="frontradio">
    <input name="type" type="radio" id="homeradio" value="home" />
    <div class="homelabel"> <label for="homeradio">Home</label></div>
    <input name="type" type="radio" id="officeradio" value="office" />
    <label for="officeradio">Office</label>
  </div>
  <div class="homebutton">
    <input type='submit' id="submithome" name="did_submit" value="Get Started!">
  </div>
</form>

A closing note, your code should verify there is a value selected for the service dropdown and just return errors instead of forcing the user around.

PS - your submission handling needs to be done BEFORE any html is sent to the browser. My example does not properly show a separation. It looks inline but that is not the intention. The form check code should happen as close to the top of the file as possible

JAVASCRIPT EXAMPLE:

<script type="text/javascript">
    var sandiego = ['91911', '91914', '91915', '91932', '91942', '91945', '91950', '92014', '92025', '92027', '92029', '92037', '92064', '92065', '92067', '92071', '92075', '92101', '92102', '92103', '92104', '92105', '92106', '92107', '92108', '92109', '92110', '92111', '92113', '92114', '92115', '92116', '92117', '92118', '92119', '92120', '92121', '92122', '92123', '92124', '92126', '92127', '92128', '92129', '92130', '92131', '92132', '92134', '92135', '92139', '92140', '92145', '92147', '92154', '92173'];
    var selection, zip, home;

    function sendForm(){
        zip = document.getElementById("selection").value;

        if(inArray(zip, sandiego))
        {
            selection = document.getElementById("selection").value;
            if(selection != "")
            {
                home = document.getElementById("home").value;
                var url = selection + '?zip=' + zip + '&home=' + home;
                window.location = url;
            }            
        }
        else
        {
            window.location = 'http://www.pureflo.com/';
        }
    }

    function inArray(needle, haystack) {
        var length = haystack.length;
        for(var i = 0; i < length; i++) {
            if(haystack[i] == needle) return true;
        }
        return false;
    }
</script>

check the method of your from :) and after the header() use exit to prevent further execution of the php

<?php
    $zip = $_POST['zip']; //your form method is post

    $sandiego =  array('91911', '91914', '91915', '91932', '91942', '91945', '91950', '92014', '92025', '92027', '92029', '92037', '92064', '92065', '92067', '92071', '92075', '92101', '92102', '92103', '92104', '92105', '92106', '92107', '92108', '92109', '92110', '92111', '92113', '92114', '92115', '92116', '92117', '92118', '92119', '92120', '92121', '92122', '92123', '92124', '92126', '92127', '92128', '92129', '92130', '92131', '92132', '92134', '92135', '92139', '92140', '92145', '92147', '92154', '92173');

    if (in_array($zip, $sandiego)){
        header("Location: ".$_POST['selection']);
        exit;
    } else {
            header("Location: http://www.pureflo.com/");
            exit; 
   }

?>