-1

I need to create a simple postcode / page finder for a site where a user will enter their postcode and be redirected to a page based on whether or not that location is covered by the company.

Basically the same as used on this site: http://www.dailypoppins.co.uk/

The fact it is a postcode is kind of irrelevant. For simplicity I'd probably just like a PHP file which takes the value entered into the form, checks it against a predefined list of values (Postcodes, there aren't that many currently covered) and then redirects the user to the correct page depending on the value / postcode entered.

Does anyone know how to do this?

Nanne
  • 64,065
  • 16
  • 119
  • 163
Philip Benton
  • 119
  • 1
  • 4
  • 1
    Plenty of us know how to do it, but we're not going to write your code for you: what have you tried? - http://mattgemmell.com/2008/12/08/what-have-you-tried/ – Mark Baker Jan 31 '13 at 10:36
  • I wonder if you mean the prefix of the postcode? eg GU[a number] means Guidlford, or are you really checking the whole postcode "GU3 1XX", cause that is a lot of postcodes ... – Cups Jan 31 '13 at 11:33

1 Answers1

0

This is a simple example..

$validPostcodes = array('123', '456', '789');

// get form value
$postcode = $_GET['postcode'];

if (isset($validPostcodes[$postcode])) {
    header('Location: http://www.newsite.com/'.$postcode);
}
else {
    echo 'Postcode does not exist';
}

Like I said..this is only a very simple example. I might be better to have the postcodes stored in a database and do some error checking on the form value.

I suggest to read about PHP form validation and PHP database access and of course HTML forms.

PHP database access 1, PHP database access 2, PHP Form handling, HTML forms

bitWorking
  • 12,485
  • 1
  • 32
  • 38