evilmonkey646 Posted August 26, 2010 Share Posted August 26, 2010 How to make a form using HTML/PHP with conditional responses based on zip code? What I want to do exactly... zip codes 91900-92600 go to URL www.example.com after submit. All others go to URL www.example.com/page after submit. Any help would be much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/211751-how-to-make-a-form-using-htmlphp-with-conditional-responses-based-on-zip-code/ Share on other sites More sharing options...
fortnox007 Posted August 26, 2010 Share Posted August 26, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/211751-how-to-make-a-form-using-htmlphp-with-conditional-responses-based-on-zip-code/#findComment-1103764 Share on other sites More sharing options...
MadTechie Posted August 26, 2010 Share Posted August 26, 2010 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' ) } } Quote Link to comment https://forums.phpfreaks.com/topic/211751-how-to-make-a-form-using-htmlphp-with-conditional-responses-based-on-zip-code/#findComment-1103836 Share on other sites More sharing options...
fortnox007 Posted August 26, 2010 Share Posted August 26, 2010 Awesome! I assumed it, but you just put the cherry on top Quote Link to comment https://forums.phpfreaks.com/topic/211751-how-to-make-a-form-using-htmlphp-with-conditional-responses-based-on-zip-code/#findComment-1103847 Share on other sites More sharing options...
MadTechie Posted August 26, 2010 Share Posted August 26, 2010 We should also state that you process the data BEFORE redirecting Quote Link to comment https://forums.phpfreaks.com/topic/211751-how-to-make-a-form-using-htmlphp-with-conditional-responses-based-on-zip-code/#findComment-1103866 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.