Customized Form based on zip code

timhersh

New Member
Need help

I have a insurance website we are designing. There will be an "Easy Quote" link.

This page will have a box where the user types their zip code. Once they click go I need to somehow check that zip code against a list of them (total 10). Based on which zip code they enter the program needs to decide which page it sends them to. For example if they enter 63334 they will go to quote3.php, if they enter 63323 they will go to quote5.php (different offices quote sheet).

Also for one zip we would like to alternate which form they go to, so the first time someone enters 62230 they will go to quote1.php, the next time quote2.php, then back to quote1.php

any ideas or help would be appreciated.
 

Ignis

New Member
It sounds like simple header usage.

for the server side code in PHP (after the form is set) you can do this.

start.php(form here, user hits submit)>retrieval.php

I'm going to assume two things, you used POST at the contact form, and that the text entry element was named "zip_code"

retrieval.php

Code:
<?php
     switch($_POST['zip_code'])
              {
              case '63323':
                               header("location:quote5.php");
                               exit;
              case '63334':
                               header("location:quote3.php");
                               exit;
              default:
                               //Human beings make mistakes, you can send them 
                               //back to the previous page with an error message
                               header("location:start.php?error=We do not have a page for your specified zip code.");
                               exit;
              }
?>

Also for one zip we would like to alternate which form they go to, so the first time someone enters 62230 they will go to quote1.php, the next time quote2.php, then back to quote1.php

That might be a bit tricky, the server needs a way to track that variable. Eg. which one was last used.

If you aren't using a database a text file is sufficient I suppose, or some php functionality to retain a server side variable I'm unaware of (this isn't related to one user's session after all, but of all the users are visiting it).

However if you just want that accessed 50% of the time you can do something like...


Code:
<?php
     switch($_POST['zip_code'])
              {
              case '62230':
                               if(mt_rand(1, 100) > 50)
                                 header("location:quote1.php");
                               else
                                header("location:quote2.php");
                               exit;
              case '63323':
                               header("location:quote5.php");
                               exit;
              case '63334':
                               header("location:quote3.php");
                               exit;
              default:
                               //Human beings make mistakes, you can send them 
                               //back to the previous page with an error message
                               header("location:start.php?error=We do not have a page for your specified zip code.");
                               exit;
              }
?>
 
Top