Jump to content

How to make a form using HTML/PHP with conditional responses based on zip code?


evilmonkey646

Recommended Posts

Well I think there are more solutions, but I think if you put an if-clause at the beginning of your script  that checks if the submit button is pressed and checks the zip i think your already there.

here goes nothing ;)

 

Put the following before the <html> element (also this requires you to use the post method action and 'submit as name for the submit button, and zipcode as html variable.

 

<?php
       //retrieve zip variable from the html form
           $zip = $_POST['zipcode'];

           // the if-clause
           if(isset($_POST['submit'])){ // so if submit is pressed....
                if ($zip!=''&& $zip >= 91900 && $zip <= 92600){      // if $zip is not empty, and 91900-92600, execute

                header( 'Location: http://www.yoursite.com/zip_page.html' ) ; // the header will automatically redirect
             }
           }
       
?>

 

Hope this helps a bit ;-) good luck have fun!

Link to comment
Share on other sites

When you say "after submit." do you mean the user ends on that page or the script processes the data on that page,

if its just where the user ends up then have your form post to a "processing page" and then have a  condition to redirect you

(revised code from fortnox007)

// the if-clause
           if(isset($_POST['submit'])){
                      $zip = $_POST['zipcode'];
                      if ($zip!=''&& $zip >= 91900 && $zip <= 92600){
                                 header( 'Location: http://www.yoursite.com/zip_page.html' ) ; // the header will automatically redirect
                      }else{
                                 header( 'Location: http://www.yoursite.com/nonzip_page.html' ) 
                      }
           }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.