pock0 Posted June 7, 2014 Share Posted June 7, 2014 Hi, can anyone help me? I am trying to create a form which asks the user to input their postcode then submit. the purpose is so if the service my site offers is not available in the location that the end user lives, then I want to display a message saying 'Sorry, not available', but if they are in area then it redirects to another page. My form code is: <form method="post" action="forwarder.php"> <p> Enter Post Code Here:<input type = "text" name = "zip" id = "zip" size = "10" maxlength = "5" "> <input type='submit'> </form> My PHP is: <?php $zip = isset ($_POST['zip']) { if ($zip=='NG15') { header('Location: https://www.bing.com'); } else { header('Location: http://www.google.co.uk') } ?> I am a bit of a newbie at this, and I know my PHP won't give me my desired result, but I was using this to try and test the concept. Help would be really appreciated, and if you can show me how to do it for multiple postcodes even better Quote Link to comment https://forums.phpfreaks.com/topic/289049-redirect-based-on-postcodezip-code/ Share on other sites More sharing options...
Barand Posted June 7, 2014 Share Posted June 7, 2014 (edited) isset() return true or false, not the value of of the variable being tested. if (isset($_POST['zip']) && $_POST['zip'] != '') { if ($_POST['zip'] == 'NG15' { header('Location: https://www.bing.com'); } else { header('Location: http://www.google.co.uk') } } else { header("Location: postcodeform.html"); } For multiple postcodes you have several choices array text file database If you use an array, the test would be like this $codes = array( 'NG15', 'NG12', 'NG1' ); if (in_array($_POST['zip'], $codes)) If you use the other two then you could read from the db or text file and put the codes into an array then the processing from then on would be the same Edited June 7, 2014 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/289049-redirect-based-on-postcodezip-code/#findComment-1482162 Share on other sites More sharing options...
pock0 Posted June 7, 2014 Author Share Posted June 7, 2014 Thanks Barand I will give it a go Quote Link to comment https://forums.phpfreaks.com/topic/289049-redirect-based-on-postcodezip-code/#findComment-1482165 Share on other sites More sharing options...
pock0 Posted June 7, 2014 Author Share Posted June 7, 2014 Im not getting much luck. When I hit submit I just get a blank page, any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/289049-redirect-based-on-postcodezip-code/#findComment-1482168 Share on other sites More sharing options...
Barand Posted June 7, 2014 Share Posted June 7, 2014 Do you have any error reporting turned on? If not, put this at top of your page ini_set ("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/289049-redirect-based-on-postcodezip-code/#findComment-1482170 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.